Вопрос

Я разработал небольшое приложение формы C #, которое вызывает веб-сервис. Все работает красиво, но мне нужно держать штат и делать то, что мне нужно использовать CookieContainer, если я не ошибаюсь.

Я создал ссылку на сервис, используя меню «Добавить ссылку на сервис» моего проекта, и все работало красиво. Но я не знаю, как добавить cookiemanager на созданный клиент.

Я нашел несколько примеров, которые показали образцы, такие как:

serviceClient.CookieContainer=new CookieContainer()

Но это не так. Мой сервисный клиент не имеет такой собственности. Кстати, я вьюкую визуальную студию 2010 бета.

Заранее спасибо!

Это полученный сервис (который был создан автоматически):

//------------------------------------------------------------------------------

// // Этот код был сгенерирован инструментом. // Версия Runtime: 4.0.30128.1 // // Изменения в этом файле могут привести к неправильному поведению и будет потеряно, если // код регенерирован. // // ---------------------------------------------------- -------------------------------------

пространство имен WSClient.securityServicereference {

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://max/", ConfigurationName="SecurityServiceReference.SecurityService")]
public interface SecurityService {

    // CODEGEN: Generating message contract since element name return from namespace  is not marked nillable
    [System.ServiceModel.OperationContractAttribute(Action="http://max/SecurityService/nextValRequest", ReplyAction="http://max/SecurityService/nextValResponse")]
    [System.ServiceModel.TransactionFlowAttribute(System.ServiceModel.TransactionFlowOption.Allowed)]
    WSClient.SecurityServiceReference.nextValResponse nextVal(WSClient.SecurityServiceReference.nextValRequest request);

    // CODEGEN: Generating message contract since element name return from namespace  is not marked nillable
    [System.ServiceModel.OperationContractAttribute(Action="http://max/SecurityService/reportSessionIDRequest", ReplyAction="http://max/SecurityService/reportSessionIDResponse")]
    [System.ServiceModel.TransactionFlowAttribute(System.ServiceModel.TransactionFlowOption.Allowed)]
    WSClient.SecurityServiceReference.reportSessionIDResponse reportSessionID(WSClient.SecurityServiceReference.reportSessionIDRequest request);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class nextValRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Name="nextVal", Namespace="http://max/", Order=0)]
    public WSClient.SecurityServiceReference.nextValRequestBody Body;

    public nextValRequest() {
    }

    public nextValRequest(WSClient.SecurityServiceReference.nextValRequestBody Body) {
        this.Body = Body;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.Runtime.Serialization.DataContractAttribute()]
public partial class nextValRequestBody {

    public nextValRequestBody() {
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class nextValResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Name="nextValResponse", Namespace="http://max/", Order=0)]
    public WSClient.SecurityServiceReference.nextValResponseBody Body;

    public nextValResponse() {
    }

    public nextValResponse(WSClient.SecurityServiceReference.nextValResponseBody Body) {
        this.Body = Body;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.Runtime.Serialization.DataContractAttribute(Namespace="")]
public partial class nextValResponseBody {

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=0)]
    public string @return;

    public nextValResponseBody() {
    }

    public nextValResponseBody(string @return) {
        this.@return = @return;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class reportSessionIDRequest {

    [System.ServiceModel.MessageBodyMemberAttribute(Name="reportSessionID", Namespace="http://max/", Order=0)]
    public WSClient.SecurityServiceReference.reportSessionIDRequestBody Body;

    public reportSessionIDRequest() {
    }

    public reportSessionIDRequest(WSClient.SecurityServiceReference.reportSessionIDRequestBody Body) {
        this.Body = Body;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.Runtime.Serialization.DataContractAttribute()]
public partial class reportSessionIDRequestBody {

    public reportSessionIDRequestBody() {
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class reportSessionIDResponse {

    [System.ServiceModel.MessageBodyMemberAttribute(Name="reportSessionIDResponse", Namespace="http://max/", Order=0)]
    public WSClient.SecurityServiceReference.reportSessionIDResponseBody Body;

    public reportSessionIDResponse() {
    }

    public reportSessionIDResponse(WSClient.SecurityServiceReference.reportSessionIDResponseBody Body) {
        this.Body = Body;
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.Runtime.Serialization.DataContractAttribute(Namespace="")]
public partial class reportSessionIDResponseBody {

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=0)]
    public string @return;

    public reportSessionIDResponseBody() {
    }

    public reportSessionIDResponseBody(string @return) {
        this.@return = @return;
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface SecurityServiceChannel : WSClient.SecurityServiceReference.SecurityService, System.ServiceModel.IClientChannel {
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class SecurityServiceClient : System.ServiceModel.ClientBase<WSClient.SecurityServiceReference.SecurityService>, WSClient.SecurityServiceReference.SecurityService {

    public SecurityServiceClient() {
    }

    public SecurityServiceClient(string endpointConfigurationName) : 
            base(endpointConfigurationName) {
    }

    public SecurityServiceClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public SecurityServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress) {
    }

    public SecurityServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress) {
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    WSClient.SecurityServiceReference.nextValResponse WSClient.SecurityServiceReference.SecurityService.nextVal(WSClient.SecurityServiceReference.nextValRequest request) {
        return base.Channel.nextVal(request);
    }

    public string nextVal() {
        WSClient.SecurityServiceReference.nextValRequest inValue = new WSClient.SecurityServiceReference.nextValRequest();
        inValue.Body = new WSClient.SecurityServiceReference.nextValRequestBody();
        WSClient.SecurityServiceReference.nextValResponse retVal = ((WSClient.SecurityServiceReference.SecurityService)(this)).nextVal(inValue);
        return retVal.Body.@return;
    }

    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    WSClient.SecurityServiceReference.reportSessionIDResponse WSClient.SecurityServiceReference.SecurityService.reportSessionID(WSClient.SecurityServiceReference.reportSessionIDRequest request) {
        return base.Channel.reportSessionID(request);
    }

    public string reportSessionID() {
        WSClient.SecurityServiceReference.reportSessionIDRequest inValue = new WSClient.SecurityServiceReference.reportSessionIDRequest();
        inValue.Body = new WSClient.SecurityServiceReference.reportSessionIDRequestBody();
        WSClient.SecurityServiceReference.reportSessionIDResponse retVal = ((WSClient.SecurityServiceReference.SecurityService)(this)).reportSessionID(inValue);
        return retVal.Body.@return;
    }
}

}

Это было полезно?

Решение

Эта ссылка на обслуживание в созданном с использованием WCF и WCF независима от фактической среды связи, которая означает, что эти сервисы могут использоваться либо с использованием WebService или Remoting, либо MSMQ. И удаление и MSMQ не имеет концепции файлов cookie.

Лучше Создайте ссылку на веб-сервисе с помощью WSDL.exe и добавьте полученный класс в вашем проекте. Я сделал то же самое.

Другие советы

Зачем вернуться к старым технологиям, когда вы можете просто включить куки на привязке?

http://megakemp.wordpress.com/2009/02/06/managing-shared-cookies-in-wcf/

Quicked: Если метод веб-сервиса XML использует состояние сеанса, то файл cookie передается в заголовки ответа к клиенту веб-службы XML, который однозначно идентифицирует сеанс для этого клиента XML веб-сервиса. Для того, чтобы веб-сервис XML для обслуживания состояния сеанса для клиента клиент должен хранить cookie.

Больше информации: http://msdn.microsoft.com/en-us/library/system.web.services.protocols.httpwebclientprotocol.cookiContainer.aspx.cookiecontainer.aspx.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top