wsdl中的php soap wsdlaction属性,有什么用

没有更多推荐了,
不良信息举报
举报内容:
soap和wsdl的理解
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!用cxf开发一个WebService很简单,只需要下面几步:
1.定义接口
public interface HelloService {
String hello();
public class HelloServiceImpl implements HelloService {
public String hello() {
return "hi,my name is gyoung ";
3.用ServerFactoryBean生成服务
public static void main(String[] args) {
HelloServiceImpl helloworldImpl = new HelloServiceImpl();
//cxf发布服务的工厂bean
ServerFactoryBean svrFactory = new ServerFactoryBean();
//设置服务类
svrFactory.setServiceClass(HelloService.class);
//设置服务地址
svrFactory.setAddress("http://localhost:9001/Hello");
//设置服务bean
svrFactory.setServiceBean(helloworldImpl);
svrFactory.create();
这样,一个简单的HelloWorld服务便生成成功了。
但是,这样生成的服务有一个问题,wsdl中的soapAction属性是空的
&wsdl:binding name="HelloServiceSoapBinding" type="tns:HelloServicePortType"&
&soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&
&wsdl:operation name="hello"&
&soap:operation soapAction="" style="document"/&
&wsdl:input name="hello"&
&soap:body use="literal"/&
&/wsdl:input&
&wsdl:output name="helloResponse"&
&soap:body use="literal"/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
这一段&soap:operation soapAction="" style="document"/&,如果是.net生成的服务,soapAction是有值的
&wsdl:binding name="WebService1Soap" type="tns:WebService1Soap"&
&soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&
&wsdl:operation name="HelloWorld"&
&soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/&
&wsdl:input&
&soap:body use="literal"/&
&/wsdl:input&
&wsdl:output&
&soap:body use="literal"/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
查看了很久的源码,才发现,设置cxf设置soapAction是在org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean类中
它会去循环遍历serviceConfigurations,调用其getAction方法来获取action的值。但初始的serviceConfigurations只有DefaultServiceConfiguration和SoapBindingServiceConfiguration,这两个类都没有实现其基类AbstractServiceConfiguration中的getAction方法。所以getAction返回值是空,所以wsdl中的soapAction值也会是空。找到问题就好办了,我们在serviceConfigurations中增加一个config,在AbstractServiceConfiguration的众多子类中,我发现MethodNameSoapActionServiceConfiguration有继承getAction方法,所以我们只需要在生成服务的时候,增加一个MethodNameSoapActionServiceConfiguration
配置就行了。
public static void main(String[] args) {
HelloServiceImpl helloworldImpl = new HelloServiceImpl();
//cxf发布服务的工厂bean
ServerFactoryBean svrFactory = new ServerFactoryBean();
svrFactory.getServiceFactory().getConfigurations().add(new MethodNameSoapActionServiceConfiguration());
//设置服务类
svrFactory.setServiceClass(HelloService.class);
//设置服务地址
svrFactory.setAddress("http://localhost:9001/Hello");
//设置服务bean
svrFactory.setServiceBean(helloworldImpl);
svrFactory.create();
最张生成的wsdl
&wsdl:binding name="HelloServiceSoapBinding" type="tns:HelloServicePortType"&
&soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/&
&wsdl:operation name="hello"&
&soap:operation soapAction="hello" style="document"/&
&wsdl:input name="hello"&
&soap:body use="literal"/&
&/wsdl:input&
&wsdl:output name="helloResponse"&
&soap:body use="literal"/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
当然,我们也可以自己继承AbstractServiceConfiguration来实现getAction方法。
阅读(...) 评论()关于webservice用soap调用怎么写
[问题点数:100分,结帖人shuai]
关于webservice用soap调用怎么写
[问题点数:100分,结帖人shuai]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2013年3月 总版技术专家分月排行榜第二
2014年2月 Java大版内专家分月排行榜第一2013年8月 Java大版内专家分月排行榜第一2013年5月 Java大版内专家分月排行榜第一2013年4月 Java大版内专家分月排行榜第一2013年3月 Java大版内专家分月排行榜第一2013年2月 Java大版内专家分月排行榜第一
匿名用户不能发表回复!|没有更多推荐了,
不良信息举报
举报内容:
Web Service学习笔记(webservice、soap、wsdl、jws详细分析)
举报原因:
原文地址:
原因补充:
最多只允许输入30个字
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!&&&&& 在Web Services方法进行通信使用SOAP遵循标准的SOAP格式,该格式的一部分是在XML文档中编码的数据。XML文档包含一个Envelope根元素(由必需的Body元素和可选的Header元素构成)。Body元素由特定于消息的数据构成。可选的Header元素可以包含不与特定消息直接相关的其他信息。
&&&&& 一、定义和处理SOAP Header
&&&&& 在ASP.NET创建的Web Services可以定义和操作SOAP Header。通过在特定的SOAP Header中定义数据类并从SoapHeader类(在System.Web.Services.Protocols命名空间下)派生,便可完成SOAP Header的定义。
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService_SoapHeader : System.Web.Services.WebService
//定义MySoapHeader变量用来保存SoapHeader值
public MySoapHeader mySoapH
[WebMethod]
[SoapHeader("mySoapHeader")]
public string HelloWorld(string name)
return "Hello,"+
public class MySoapHeader : SoapHeader
public int UserID;
public DateTime LoginT
public string UserN
&&&&&& 查看生成的SOAP的Post内容:
POST /WebService_SoapHeader.asmx HTTP/1.1
Host: localhost
Content-Type: text/ charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"
&?xml version="1.0" encoding="utf-8"?&
&soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
&soap:Header&
&MySoapHeader xmlns="http://tempuri.org/"&
&UserID&int&/UserID&
&LoginTime&dateTime&/LoginTime&
&UserName&string&/UserName&
&/MySoapHeader&
&/soap:Header&
&soap:Body&
&HelloWorld xmlns="http://tempuri.org/"&
&name&string&/name&
&/HelloWorld&
&/soap:Body&
&/soap:Envelope&
&&&&& 二、客户端使用Soap Header
&&&&& 引用或使用Wsdl.exe工具可以生成Web Services的引用辅助类。Web Services定义的Soap Header会生成对应的代码:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://tempuri.org/")]
public partial class MySoapHeader : object, System.ComponentModel.INotifyPropertyChanged {
private int userIDF
private System.DateTime loginTimeF
private string userNameF
private System.Xml.XmlAttribute[] anyAttrF
/// &remarks/&
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public int UserID {
return this.userIDF
this.userIDField = value;
this.RaisePropertyChanged("UserID");
/// &remarks/&
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public System.DateTime LoginTime {
return this.loginTimeF
this.loginTimeField = value;
this.RaisePropertyChanged("LoginTime");
/// &remarks/&
[System.Xml.Serialization.XmlElementAttribute(Order=2)]
public string UserName {
return this.userNameF
this.userNameField = value;
this.RaisePropertyChanged("UserName");
/// &remarks/&
[System.Xml.Serialization.XmlAnyAttributeAttribute()]
public System.Xml.XmlAttribute[] AnyAttr {
return this.anyAttrF
this.anyAttrField = value;
this.RaisePropertyChanged("AnyAttr");
public event System.ComponentModel.PropertyChangedEventHandler PropertyC
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyC
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
&&&&&& 对于Web Method,Soap Header会变成Web Method的第一个参数:
public string HelloWorld(Client.SoapHeaderService.MySoapHeader MySoapHeader, string name) {
Client.SoapHeaderService.HelloWorldRequest inValue = new Client.SoapHeaderService.HelloWorldRequest();
inValue.MySoapHeader = MySoapH
inValue.name =
Client.SoapHeaderService.HelloWorldResponse retVal = ((Client.SoapHeaderService.WebService_SoapHeaderSoap)(this)).HelloWorld(inValue);
return retVal.HelloWorldR
&&&&&& 客户端测试代码,首先定义Soap Header,再把Soap Header作为Web Method的参数传递:
static void Main(string[] args)
SoapHeaderService.WebService_SoapHeaderSoapClient client = new SoapHeaderService.WebService_SoapHeaderSoapClient();
SoapHeaderService.MySoapHeader soapHeader = new SoapHeaderService.MySoapHeader();
soapHeader.UserID = 1;
soapHeader.UserName = "User1";
soapHeader.LoginTime = DateTime.N
client.HelloWorld(soapHeader, "UserA");
&&&&&& 利用tcpTrace可以查看Post的内容:
&&&&&&& 在Web Service的Web Method接收到Soap Header:
&&&&& 三、SoapHeader的Direction属性
&&&&& SoapHeaderDirection有四个值,分别为In、Out、InOut、Flaut。模式值是In。
&&&&& 1、使用In定义Soap Header,In方式跟上面的例子一样。
&&&&& 2、使用Out定义Soap Header:
public class WebService_SoapHeader : System.Web.Services.WebService
public MySoapHeader mySoapH
[WebMethod]
[SoapHeader("mySoapHeader",Direction=SoapHeaderDirection.Out)]
public string HelloWorld(string name)
return "Hello,"+
&&&&& Soap的Reaspone内容:
HTTP/1.1 200 OK
Content-Type: text/ charset=utf-8
Content-Length: length
&?xml version="1.0" encoding="utf-8"?&
&soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
&soap:Header&
&MySoapHeader xmlns="http://tempuri.org/"&
&UserID&int&/UserID&
&LoginTime&dateTime&/LoginTime&
&UserName&string&/UserName&
&/MySoapHeader&
&/soap:Header&
&soap:Body&
&HelloWorldResponse xmlns="http://tempuri.org/"&
&HelloWorldResult&string&/HelloWorldResult&
&/HelloWorldResponse&
&/soap:Body&
&/soap:Envelope&
&&&&&& 3、使用InOut定义Soap Header:
[WebMethod]
[SoapHeader("mySoapHeader",Direction=SoapHeaderDirection.InOut)]
public string HelloWorld(string name)
return "Hello,"+
&&&&&& Soap的Request:
POST /WebService_SoapHeader.asmx HTTP/1.1
Host: localhost
Content-Type: text/ charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"
&?xml version="1.0" encoding="utf-8"?&
&soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
&soap:Header&
&MySoapHeader xmlns="http://tempuri.org/"&
&UserID&int&/UserID&
&LoginTime&dateTime&/LoginTime&
&UserName&string&/UserName&
&/MySoapHeader&
&/soap:Header&
&soap:Body&
&HelloWorld xmlns="http://tempuri.org/"&
&name&string&/name&
&/HelloWorld&
&/soap:Body&
&/soap:Envelope&
&&&&&& Soap的Response:
HTTP/1.1 200 OK
Content-Type: text/ charset=utf-8
Content-Length: length
&?xml version="1.0" encoding="utf-8"?&
&soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
&soap:Header&
&MySoapHeader xmlns="http://tempuri.org/"&
&UserID&int&/UserID&
&LoginTime&dateTime&/LoginTime&
&UserName&string&/UserName&
&/MySoapHeader&
&/soap:Header&
&soap:Body&
&HelloWorldResponse xmlns="http://tempuri.org/"&
&HelloWorldResult&string&/HelloWorldResult&
&/HelloWorldResponse&
&/soap:Body&
&/soap:Envelope&
&&&&&& 4、使用Fault定义Soap Header
[WebMethod]
[SoapHeader("mySoapHeader",Direction=SoapHeaderDirection.Fault)]
public string HelloWorld(string name)
return "Hello,"+
&&&&&&& 使用Fault,Soap的描述跟使用Out基本一致:
HTTP/1.1 200 OK
Content-Type: text/ charset=utf-8
Content-Length: length
&?xml version="1.0" encoding="utf-8"?&
&soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&
&soap:Header&
&MySoapHeader xmlns="http://tempuri.org/"&
&UserID&int&/UserID&
&LoginTime&dateTime&/LoginTime&
&UserName&string&/UserName&
&/MySoapHeader&
&/soap:Header&
&soap:Body&
&HelloWorldResponse xmlns="http://tempuri.org/"&
&HelloWorldResult&string&/HelloWorldResult&
&/HelloWorldResponse&
&/soap:Body&
&/soap:Envelope&
&&&&&& 四、处理未知的Soap Header
&&&&& ASP.NET Web Service通过SoapUnknownHeader来标识未知的Soap Header,SOAP规范通过mustUnderstand特性来表示对Soap Header的要求,当mustUnderstand特性设置为true时,如果传入未知的Soap Header将引发异常。
&&&&& 注意:ASP.NET 使用DidUnderstand 属性来与 Web Services的方法进行通信。它不属于 SOAP 规范;它的值不会出现在 SOAP 请求或 SOAP 响应的任何部分中。
&&&&& 五、Soap Header的异常处理
&&&&& 当 Web Services检测到与处理 SOAP Header有关的错误时,应该会引发 SoapHeaderException。利用此异常类,Web Services可以正确地设置响应的格式。
阅读(...) 评论()

我要回帖

更多关于 根据wsdl生成soap报文 的文章

 

随机推荐