在没有服务引用的情况下使用HttpWebRequest动态使用Web服务 [英] Consume web service dynamically using HttpWebRequest without service reference

查看:167
本文介绍了在没有服务引用的情况下使用HttpWebRequest动态使用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的应用程序必须将数据发送到外部系统.系统系统将具有Web服务(C#或Java或PHP),我需要使用它.由于将有与客户机一样多的外部系统,因此我需要获取WSDL文件,方法名称和参数作为用户输入,并将数据发送到外部系统.

The application I work will have to send data to external system. The system system will have a web service (c# or java or php) and I need to consume it. Since there will be as many external system as clients, I need to get the WSDL file, method name and parameters as user input and send the data to the external system.

因此,我试图使用此处

我测试了一些可用的免费Web服务此处

I tested few free web services available here

我从WSDL文件中找到SOAP位置,方法名称和参数,并提供与输入相同的名称.

I find the SOAP location, method name and parameters from the the WSDL file and give the same as input.

以下服务正常工作

http://soaptest.parasoft.com/calculator.wsdl
Location - http://ws1.parasoft.com/glue/calculator
Method Name - add
Parameter - x,y

但是当我通过提供SOAP位置和方法名称为另一个免费服务尝试相同操作时,它会引发500内部服务器错误.

But when I tried the same for the another free service by providing the SOAP location, and method name it throws 500 Internal server error.

http://www.predic8.com:8080/crm/CustomerService?wsdl
Location - http://www.predic8.com:8080/crm/CustomerService
Method Name - getAll

我通过在soapUI中测试上述wsdl来确认这些输入是正确的.在soapUI请求窗口中使用相同的位置.

I confirmed these inputs are correct by testing the above wsdl in soapUI. The same location is used in soapUI request window.

我不确定为什么会引发错误.请帮助我理解它.

I am not sure why it throws error. Please help me understand it.

也请让我知道是否可以从WSDL文件中获取服务位置并使用HttpWebRequest来获取响应.无论使用哪种技术来实现Web服务,我都担心这种调用Web服务的方法是否行得通.

Also please let me know if it is fine to get the service location from WSDL file and use the HttpWebRequest to get the response. I am afraid whether this method of invoking the web service will work irrespective the technology used to implement the web service.

问题似乎出在SOAP信封上.

The problem seems to with the SOAP envelope.

对于 http://soaptest.parasoft.com/calculator.wsdl ,即使我们忽略xmlns:cal ="http://www.parasoft.com/wsdl/calculator/,它将成功执行.

For http://soaptest.parasoft.com/calculator.wsdl even if we ignore xmlns:cal="http://www.parasoft.com/wsdl/calculator/, it gets executed successfully.

但是对于 http://www.predic8.com:8080/crm/CustomerService ?wsdl ,如果我忽略xmlns:ns ="http://predic8.com/wsdl/crm/CRMService/1/,则会引发内部服务器错误.

But for http://www.predic8.com:8080/crm/CustomerService?wsdl , if I ignore xmlns:ns="http://predic8.com/wsdl/crm/CRMService/1/, it throws internal server error.

请在此处分享我的通用方式

Please share how I can be generic here

推荐答案

问题似乎出在您正在使用的请求数据上.请求验证失败,错误也是如此.

The problem appears to be with request data that you are using. The request is failing validation, so is the error.

如果您导入提供的 wsdl ,并验证创建请求,很清楚问题出在哪里.

If you import the provided wsdl, and validate create request, it is clear what the problem is.

PersonCustomer下有一个元素id,数据必须遵循在模式../common/1

There is an element id under Person and Customer and data must follow certain patter which is defined under the schema ../common/1

这是架构引用,具有simpleType 限制:

Here is the schema reference, which has simpleType restriction:

   <xsd:simpleType name="IdentifierType">
      <xsd:annotation>
         <xsd:documentation>Identifier for business objects.</xsd:documentation>
      </xsd:annotation>
      <xsd:restriction base="xsd:string">
         <xsd:pattern value="[A-Z]{2}-\d{5}"/>
      </xsd:restriction>
   </xsd:simpleType>

因此,id的值应类似于AA-12345,即两个大写字母,连字符(-),后跟5位数字.

So, id value should Something like AA-12345 i.e., two Capital letter, hyphen(-), and followed by 5 digits.

按照上述模式更改您的请求,您应该会很好.

Change your request as per above pattern, and you should be good.

希望这会有所帮助.

这篇关于在没有服务引用的情况下使用HttpWebRequest动态使用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆