Law*_*nce 11 c# soap web-services
我有一个SOAP WSDL(在这里找到:https://portal.bsh-partner.com/picenter/server/a2a/),我正在尝试使用Web服务.
var soapEnvelope = string.Empty;
soapEnvelope = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
soapEnvelope += "<soapenv:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:q0=\"http://thexmlhost.com\">";
soapEnvelope += "<q0:Connect>";
soapEnvelope += "<q0:Username>username</q0:Username>";
soapEnvelope += "<q0:Password>password</q0:Password>";
soapEnvelope += "</q0:Connect>";
soapEnvelope += "</soapenv:Body>";
soapEnvelope += "</soapenv:Envelope>";
var xmlHttp = new MSXML2.ServerXMLHTTP40();
xmlHttp.open("POST", "https://thexmlhost.com/", "", "");
xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttp.setRequestHeader("SOAPAction", "thexmlhost.com/");
xmlHttp.send(soapEnvelope);
xmlHttp.waitForResponse(500);
var outXml = xmlHttp.responseText;
Run Code Online (Sandbox Code Playgroud)
响应不断返回一般HTTP响应错误页面.知道如何通过我的Soap Envelope从Web服务获得正确的响应吗?
Kie*_*one 22
如果您有WSDL,则可以在Visual Studio中创建服务引用,它将为您生成代理类.除非我在你的问题中遗漏了一些细节,否则实施和使用会更加可靠,更容易.
希望有所帮助.
我刚刚注意到你在服务器端使用这段代码.
这不是在.NET中使用Web服务的方法.使用Visual Studio中的"添加服务引用"命令创建代理类,以便您可以非常轻松地使用该服务.
有关示例,请参见如何使用Web服务,以及http://msdn.microsoft.com/wcf/.
此外,在使用XML时永远不要使用字符串操作技术.简而言之,字符串和XML的规则是不同的..NET有几个XML API可以使用XML,它们都知道规则.