我在C#中创建了一个SOAP Web服务的Web引用。 如果我浏览该服务或使用POSTMAN进行测试,我会按预期收到回复。
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:openResponse xmlns:ns1="http://auto.api.com/">
<return xmlns:ns2="http://auto.api.com/">
<error>User/pass incorrect</error>
</return>
</ns1:openResponse>
</soap:Body>
</soap:Envelope>
我在下面运行的代码非常简单,但是当它连接到服务时我收到了这个错误:
Unmarshalling Error:名称空间URI和本地名称 unmarshaller需要被实习
var connect = new SOAP();
var open = connect.open(new Open
{
user = "user",
pass = "pass"
});
有什么建议吗?我找不到任何暗示如何解决它的东西。我以前从未见过连接到Web服务的错误。
完全例外:
System.Web.Services.Protocols.SoapHeaderException:Unmarshalling 错误:unmarshaller的名称空间URI和本地名称需要 实习。在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage 消息,WebResponse响应,流responseStream,布尔值 asyncCall)at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串 methodName,Object [] parameters)at TestingConsole.web.SOAP.open(xOpen open1)in C:\用户\分\来源\回购\ TestingConsole \ WEB 参考文献\ web \ Reference.cs:第755行 TestingConsole.Form1.button1_Click(Object sender,EventArgs e)in c:\ Users \ pm \ Source \ Repos \ TestingConsole \ Form1.cs:第32行
它指的是reference.cs的一部分
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace="http://auto.api.com/", ResponseNamespace="http://auto.api.com/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public xOpenResponse open([System.Xml.Serialization.XmlElementAttribute("open", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] xOpen open1) {
object[] results = this.Invoke("open", new object[] {
open1});
return ((xOpenResponse)(results[0]));
}
完整例外作为服务参考:
System.ServiceModel.FaultException:Unmarshalling Error:Namespace 需要实现unmarshaller的URI和本地名称。
服务器堆栈跟踪:at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime 操作,ProxyRpc&amp; rpc)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局,TimeSpan超时)at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway,ProxyOperationRuntime操作,Object [] ins, 对象[]出局) System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)
在[0]处重新抛出异常:at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgstr,Int32类型)在TestingConsole.SOAP.open(打开请求)
在TestingConsole.SOAP.TestingConsole.SOAP.open(打开请求)中 C:\用户\分\来源\回购\ TestingConsole \服务 引用\ service \ Reference.cs:第7621行 TestingConsole.SOAP.open(xOpen open1)in C:\用户\分\来源\回购\ TestingConsole \服务 引用\ service \ Reference.cs:第7627行 TestingConsole.Form1.button1_Click(Object sender,EventArgs e)in c:\ Users \ pm \ Source \ Repos \ TestingConsole \ Form1.cs:第29行
reference.cs文件中的位引用:
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
TestingConsole.service.openResponse TestingConsole.service.SOAP.open(TestingConsole.service.open request) {
return base.Channel.open(request);
}
public TestingConsole.service.xOpenResponse open(TestingConsole.service.xOpen open1) {
TestingConsole.service.open inValue = new TestingConsole.service.open();
inValue.open1 = open1;
TestingConsole.service.openResponse retVal = ((TestingConsole.service.SOAP)(this)).open(inValue);
return retVal.@return;
}
答案 0 :(得分:0)
解决这个问题的答案是从Reference.cs中生成的方法中删除RequestNamespace。这意味着它将正确格式化的请求发送到服务