使用WCF从.NET访问SAP Web服务

6

我想通过WCF从.NET调用SAP Web服务。我已经生成了代理并配置了app.config文件。

这是我的测试代码:

WebServiceSAP.ZTEST_RFCClient myWCFService = new WebServiceSAP.ZTEST_RFCClient("MyEndPoint");

myWCFService.ClientCredentials.UserName.UserName = "<UserName>";
myWCFService.ClientCredentials.UserName.Password = "<Password>";

WebServiceSAP.ZTestRfc parameter = new WebServiceSAP.ZTestRfc();
parameter.TestInput = "This is a simple test";

WebServiceSAP.ZTestRfcResponse response = myWCFService.ZTestRfc(parameter);

Console.WriteLine(reponse.TestOutput);
Console.ReadLine();            

ZTestRFC SAP方法是一个非常简单的函数,它接受一个输入字符串,并输出:"Result: <输入字符串>" 当我调用ZTestRFC方法时,变量响应中出现了空值。但SOAP消息似乎没问题。 SOAP请求
<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<VsDebuggerCausalityData>uIDPoxJmI5NcDatNiPM/wFAr52kAAAAAtqHAVnNWjEeMpMExOyr/vN7OXwCJZltNnikldpg5migACQAA</VsDebuggerCausalityData>
</WebHeaders>
</HttpRequest>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:sap-com:document:sap:soap:functions:mc-style:ZTEST_RFC:ZTestRfcRequest</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ZTestRfc xmlns="urn:sap-com:document:sap:soap:functions:mc-style">
<TestInput xmlns="">This is a simple test</TestInput>
</ZTestRfc>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>

SOAP响应

<MessageLogTraceRecord>
<HttpResponse xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<StatusCode>OK</StatusCode>
<StatusDescription>OK</StatusDescription>
<WebHeaders>
<Content-Length>359</Content-Length>
<Content-Type>text/xml; charset=utf-8</Content-Type>
<Set-Cookie>MYSAPSSO2=AjExMDABAAxQMDEwMDA1MSAgICACAAMwNDADAAhEMTEgICAgIAQADDIwMTAxMTEwMTIwOQUABAAAAAgGAAFYCQABU%2f8A9jCB8wYJKoZIhvcNAQcCoIHlMIHiAgEBMQswCQYFKw4DAhoFADALBgkqhkiG9w0BBwExgcIwgb8CAQEwEzAOMQwwCgYDVQQDEwNQMTECAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTEwMTExMDEyMDk0OFowIwYJKoZIhvcNAQkEMRYEFJC%2fNFLVBnu1ZAodWTlPApEs8sApMAkGByqGSM44BAMEMDAuAhUBS844BOB%2f8NgEGuepMgLaKbVEGGUCFQFLs6HiI%21BWT1MejMqvABd3%2fJFVMw%3d%3d; path=/; domain=.<domain ... ></Set-Cookie>
<Server>SAP NetWeaver Application Server / ABAP 700</Server>
</WebHeaders>
</HttpResponse>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"></s:Header>
<SOAP-ENV:Body>
<rfc:ZTestRfcResult xmlns:rfc="urn:sap-com:document:sap:soap:functions:mc-style">
<TestOutput xmlns="">Result:</TestOutput>
</rfc:ZTestRfcResult>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</MessageLogTraceRecord>

我不知道可能发生了什么。有什么想法吗?
提前感谢。
1个回答

3

一开始看起来,似乎是在创建代理时(顺便问一下,你使用了什么技术来创建代理?),SAP告诉.NET参数和响应会在某个命名空间中,但是你将参数发送到了空命名空间("")中。这可能是为什么SAP服务返回“结果:”的原因。你可能得到了一个空响应,因为你的代理可能期望TestOutput元素在另一个命名空间中。

查看生成的代理类并查看预期的命名空间。


谢谢你的回答,约翰。我已经使用VS2008生成了代理类。我已经检查了代理中定义的命名空间,但目前还没有成功:_( 我会给你反馈的。 - Javier
@Javier:你使用了“添加 Web 引用”、“添加服务引用”,还是其他什么方式? - John Saunders
我使用了带有WSDL URL的Add Service Reference。谢谢。 - Javier
我曾经使用过VS2003和SAP .NET Connector 2.0,效果很好。不过,我会继续尝试在VS2008中解决我的问题。 - Javier
@Javier:使用“添加服务引用”是正确的技术。仔细查看Reference.cs文件并学习理解其中的内容。特别是要注意指定的命名空间。 - John Saunders
嗨@John,好久不见 :-) 只是想告诉你最终我无法使用WCF消费SAP服务,不得不使用SAP连接器组件来解决这个问题。我仍然不知道为什么 :-) 但非常感谢你的帮助! - Javier

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接