从服务引用到 Java Web 服务的调用不返回任何内容
我刚开始在 Visual Studio 中使用服务引用,并且正在尝试使用 Java Web 服务。我已使用向导添加了服务参考。该向导构建了代理代码并将端点添加到配置文件中。
Java 端点采用自定义类型作为单个参数。我已通过代理对象填充了该对象,并将其传递到对服务的调用中。但是当我查看响应对象时,所有属性都是空的。不会抛出任何错误。请注意,当我使用soapUI 时,我可以编辑XML 并将其发送到服务并成功获得响应。如果发生错误,我可以查看在soapUI 中发回的XML 错误消息。
这是调用代码:
static void CallJavaEndPoint()
{
IFX_ProductInqRq inqRQ = new IFX_ProductInqRq();
IFX_ProductInqRqCatSvcRq[] CatSvcRqCollection = new IFX_ProductInqRqCatSvcRq[1];
IFX_ProductInqRqCatSvcRq CatSvcRqItem = new IFX_ProductInqRqCatSvcRq();
IFX_ProductServiceReference.FX_Product_PortTypeClient proxy = new FX_Product_PortTypeClient();
IFX_ProductInqRs response;
// Remove other code for setting properties for brevity
CatSvcRqItem.RequestID = "123456";
CatSvcRqCollection[0] = CatSvcRqItem;
inqRQ.CatSvcRq = CatSvcRqCollection;
// reponse just comes back null, no errors
response = proxy.IFX_CustomerAccountDetailInquiry(inqRQ);
}
来自配置文件:
<basicHttpBinding>
<binding name="IFX_Product_Binding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="IFX_Product_Binding1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://example.com/EX_IFXProduct/services/Product_SoapPort_1234"
binding="basicHttpBinding" bindingConfiguration="IFX_Product_Binding"
contract="IFX_ProductServiceReference.IFX_Product_PortType"
name="Product_SoapPort_1234" />
</client>
问题:
- 我是否正确调用 Java Web 服务?
- 如何查看返回的 XML 错误?
- 我最好使用 Web 引用还是 WebRequest/HttpWebRequest 连接到此 Java Web 服务?
I'm new to using Service Reference in Visual Studio, and I'm trying to consume a Java Web Service. I've added Service Reference using the wizard. The wizard built the proxy code and added endpoints to the config file.
The Java Endpoint takes a custom type as single parameter. I've populated the object via the proxy objects and passed that in the call to the service. But when I look at the response object, all the properties are null. No error is thrown. Note, when I use soapUI I can edit and send XML to the service and successfully get a response. If an error occurs I can view the XML error message sent back in soapUI.
Here is the calling code:
static void CallJavaEndPoint()
{
IFX_ProductInqRq inqRQ = new IFX_ProductInqRq();
IFX_ProductInqRqCatSvcRq[] CatSvcRqCollection = new IFX_ProductInqRqCatSvcRq[1];
IFX_ProductInqRqCatSvcRq CatSvcRqItem = new IFX_ProductInqRqCatSvcRq();
IFX_ProductServiceReference.FX_Product_PortTypeClient proxy = new FX_Product_PortTypeClient();
IFX_ProductInqRs response;
// Remove other code for setting properties for brevity
CatSvcRqItem.RequestID = "123456";
CatSvcRqCollection[0] = CatSvcRqItem;
inqRQ.CatSvcRq = CatSvcRqCollection;
// reponse just comes back null, no errors
response = proxy.IFX_CustomerAccountDetailInquiry(inqRQ);
}
from config file:
<basicHttpBinding>
<binding name="IFX_Product_Binding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="IFX_Product_Binding1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://example.com/EX_IFXProduct/services/Product_SoapPort_1234"
binding="basicHttpBinding" bindingConfiguration="IFX_Product_Binding"
contract="IFX_ProductServiceReference.IFX_Product_PortType"
name="Product_SoapPort_1234" />
</client>
Questions:
- Am I calling the Java Web Service correctly?
- How would I view the XML error being returned?
- Am I better off using a Web Reference or the WebRequest/HttpWebRequest to connect to this Java Web Service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Fiddler 等工具检查从代码发送的请求/响应,然后将其与使用 SoapUI 发送的成功请求进行比较。
You could use a tool like Fiddler to inspect the request/response that you are sending from code and then compare that to the successful request that you send with SoapUI.
您所要做的就是查看生成的 Reference.cs 文件。将有几个不同的命名空间属性。当您使用 SoapUI 检查响应时,您将找到正确的命名空间。将 Reference.cs 文件中的所有命名空间引用替换为您在 SoapUI 响应中找到的命名空间。
完成替换命名空间后,您将看到响应现在已正确序列化。
请记住,Reference.cs 是生成的文件,更新服务引用时您会丢失更改。
What you have to do is review the generated Reference.cs file. There will be a couple of namespace attributes that differs. When you inspect the response using SoapUI you will find the correct namespace. Replace all the namespace references in the Reference.cs file with the namespace you have found in the SoapUI response.
When you finished replacing the namespaces you will see that the response is now serialized well.
Keep in mind that the Reference.cs is a generated file and that you lose the changes when you are updating the service reference.