Я пытаюсь использовать то, что, как я понимаю, более старый веб-сервис ASMX от стороннего поставщика, но хочу использовать WCF, поскольку это рекомендуемый подход для приложений нового стиля.Префикс пространства имен WCF
Когда я добавляю ссылку на службу к моему приложению в виде веб-ссылки (нажмите кнопку «Дополнительно» в диалоговом окне «Добавить ссылку на службу» и выберите «Добавить веб-ссылку»), я могу успешно использовать веб-службу. Все работает. Это, однако, старый метод настройки веб-службы, из того, что я понимаю.
Что я хочу - это сделать это через WCF, поэтому я пошел добавлять ссылку на службу, не делая этого в качестве веб-ссылки (например, добавьте диалоговое окно Service Reference, поместив адрес и нажав Go). Весь мой код, чтобы поговорить с веб-службы, кажется, работает, но я получаю следующее исключение:
System.ServiceModel.CommunicationException was unhandled by user code
HResult=-2146233087
Message=Unrecognized message version.
Source=mscorlib
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, 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 MarketVision.FulfillmentService.FulfillmentProcessors.TextWire.Processor.TextWireProxy.WS_CompanyPortType.readCompany(WSAuthentication auth)
at MarketVision.FulfillmentService.FulfillmentProcessors.TextWire.Processor.TextWireProxy.WS_CompanyPortTypeClient.readCompany(WSAuthentication auth)
at MarketVision.FulfillmentService.FulfillmentProcessors.TextWire.Processor.ServiceAgent.CreateCompany(String name)
at MarketVision.FulfillmentService.FulfillmentProcessors.TextWire.Processor.TextWireFulfillmentProcessor.FulfillOrders(IEnumerable`1 orders)
at FulfillmentService.Services.Wcf.FulfillmentService.FulfillOrders(IFulfillmentInfo fulfillmentInfo) in x:\FulfillmentService\Main\Source\Services\Wcf\FulfillmentService.cs:line 18
at SyncInvokeFulfillOrders(Object , Object[] , Object[])
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException:
Я играл вокруг с стельку, и это выглядит как простая проблема пространства имен, что я не знаю, как исправить. Вот сообщение, которое работает при настройке сервиса в качестве веб-ссылки:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="urn:webservices2_0_0"
xmlns:types="urn:webservices2_0_0/encodedTypes"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<tns:readCompany>
<auth href="#id1" />
</tns:readCompany>
<tns:WSAuthentication id="id1" xsi:type="tns:WSAuthentication">
<api_key xsi:type="xsd:string">myApiKey</api_key>
<code xsi:type="xsd:string">myCode</code>
<keyword xsi:type="xsd:string">myKeyword</keyword>
<password xsi:type="xsd:string">myPassword</password>
<username xsi:type="xsd:string">myUsername</username>
</tns:WSAuthentication>
</soap:Body>
</soap:Envelope>
И вот один, который не при настройке службы до как только ссылки на службу (не в качестве веб-ссылки):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:readCompany xmlns:q1="urn:webservices2_0_0">
<auth href="#id1"/>
</q1:readCompany>
<q2:WSAuthentication id="id1" xsi:type="q2:WSAuthentication" xmlns:q2="urn:webservices2_0_0">
<api_key xsi:type="xsd:string">myApiKey</api_key>
<code xsi:type="xsd:string">myCode</code>
<keyword xsi:type="xsd:string">myKeyword</keyword>
<password xsi:type="xsd:string">myPassword</password>
<username xsi:type="xsd:string">myUserName</username>
</q2:WSAuthentication>
</s:Body>
</s:Envelope>
Существует четкое различие между двумя сообщениями, отличными от пространств имен, но все, что я должен делать в скрипачке, - это принять сообщение, которое не работает, и изменить все пространства имен s: namespaces на мыло: и все работает , Итак, я уверен, что все, что мне нужно сделать, это изменить пространство имен так же, как я сделал с fiddler, и это должно работать с использованием WCF, но я не уверен, как это сделать.
Как вы создали прокси? Вы использовали svutil или у вас есть файл dll с контрактом на обслуживание? –
Щелкните правой кнопкой мыши узел «Ссылки на службы» в решении Visual Studio и заполните диалоговое окно «Добавить ссылку на службу», в котором указывается URL-адрес стороннего веб-сервиса (который, я считаю, по существу является svcutil, предоставляющим URL-адрес, но просто хотел быть явным о том, как Я сделал это). – meyousikmann