Необходимо обеспечить способ программного подключения к нескольким конечным точкам SOAP - PullRequest
0 голосов
/ 05 августа 2011

Дано:
Несколько клиентов со страницей Service.asmx, которая имеет некоторые веб-методы, к которым мне нужно подключиться.

Функция служебной программы, которая принимает данные для определения, какой клиентдолжен быть подключен к.Это то, что я до сих пор имею:

public static MyServiceSoapClient SoapClientFactory(string clientCode)
{
    var binding = new WSHttpBinding(SecurityMode.Message, false);
    var remoteAddress = new EndpointAddress(
        new Uri(string.Format("http://{0}.mydomain.com/Service.asmx", clientCode)),
        new UpnEndpointIdentity("myservice@domain.com"));

    return new MyServiceSoapClient(binding, remoteAddress);
}

Этот метод завершается без ошибок (примечание: я не знаю, что такое EndPointIdentity, поэтому я просто придумал строку для вставки туда ...не уверен, должно ли это быть в настройке конфигурации где-то еще или как?)

Проблема:
При попытке вызвать удаленный метод выдается исключение, и егоне очень описательный (A NullReferenceException).Вот код:

// point to the correct Service.asmx url.
var client = Util.SoapClientFactory(clientCode);

// now make the soap call.
var result = client.GetSomeStuff(someParameter); // throws the exception.

Трассировка стека:

System.NullReferenceException: Object reference not set to an instance of an object.
    Server stack trace:
    at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
    at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout)
    at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout)
    at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
    at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
    at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
    at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
    at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
    at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at ... my function call. (i.e. client.GetSomeStuff(someParameter) )

1 Ответ

1 голос
/ 16 сентября 2011

Я нашел ответ на мою проблему. Что я делаю, я создаю клиент Soap, используя конструктор по умолчанию (это всегда работает, но потом я застрял с Uri, который я настроил во время разработки). Затем я устанавливаю свойство Endpoint Address, которое работало Как колдовство!

var client = new MySoapClient();

// this can also be set using Web.config parameter now or a value stored in a database etc.
client.Endpoint.Address = new EndpointAddress("http://localhost:3000/Service.asmx");
return client;
...