[英]WCF namespace prefix
我正在嘗試使用第三方提供程序提供的我認為是較舊樣式的ASMX Web服務,但是要使用WCF,因為這是較新樣式應用程序的推薦方法。
將服務引用作為Web引用添加到應用程序時(單擊“添加服務引用”對話框中的“高級”按鈕,然后選擇“添加Web引用”),我可以成功使用Web服務。 一切正常。 但是,據我了解,這是設置Web服務的較舊樣式的方法。
我想要通過WCF進行操作,所以我添加了一個服務引用,而沒有將其作為Web引用(例如,“添加服務引用”對話框,輸入地址並單擊“轉到”)。 我所有與Web服務交談的代碼似乎都可以正常工作,但是我不斷收到以下異常:
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:
我玩過提琴手,它看起來像一個簡單的名稱空間問題,我不確定如何解決。 這是在將服務設置為Web參考時起作用的消息:
<?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>
這是將服務設置為僅服務參考(而不是Web參考)時不會出現的情況:
<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:命名空間更改為soap :,然后一切正常。 因此,我很確定我所要做的就是像使用fiddler一樣更改名稱空間,這應該可以在WCF中使用,但是我不確定如何做到這一點。
您應該嘗試使用svcutil命令行工具(打開VS Command Prompt來運行它),盡管它與VS的參考功能相似,但實際上是完全不同的代碼庫。 您可以使用它生成代理,所有客戶端類型等,就像使用服務引用功能一樣,它非常可靠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.