原贴中的内容
----------------------------------------------------part0出现问题
错误提示:
未处理的“System.InvalidOperationException”类型的异常出现在 system.web.services.dll 中。
其他信息: 无法反射方法 PresenceSupplierService.getMyWatchers。
==============================
使用呈现的wsdl生成了PresenceSupplierService.dll,并连同System.Web.Services.dll一起添加到项目的引用中,相关代码:
getMyWatchers y_object= new getMyWatchers();
y_object.presentity="sip:[email protected]:50611";
PresenceSupplierService ps=new PresenceSupplierService();//提示出错的是这步
string[] result=ps.getMyWatchers (y_object);
==============================
当我用类似方法调用PresenceNotificationService时是正常的(该service是sag上行到sp侧的,而supplierservice是sp侧下行的sag的);----------------------------------------------------part1相关信息
生成的代理类肯定有问题,我是根据parlay标准的wsdl文件生成的代理类,代理类的源码和测试程序的项目源码都可以提供,感兴趣的话可以留个邮箱给我,另外我的msn:[email protected],可以在线讨论,再回到这里来总结,下面是代理类中getMywatchers方法部分的源码(有点乱,用ultraedit打开好了):
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( " ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlArrayAttribute( "getMyWatchersResponse ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")]
[return: System.Xml.Serialization.XmlArrayItemAttribute( "result ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ", DataType= "anyURI ", IsNullable=false)]
public string[] getMyWatchers([System.Xml.Serialization.XmlElementAttribute( "getMyWatchers ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")] getMyWatchers getMyWatchers1) {
object[] results = this.Invoke( "getMyWatchers ", new object[] {
getMyWatchers1});
return ((string[])(results[0]));
}
/// <res/ >
public System.IAsyncResult BegingetMyWatchers(getMyWatchers getMyWatchers1, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke( "getMyWatchers ", new object[] {
getMyWatchers1}, callback, asyncState);
}
/// <res/ >
public string[] EndgetMyWatchers(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string[])(results[0]));
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")]
public class getMyWatchers {
/// <res/ >
[System.Xml.Serialization.XmlElementAttribute(DataType= "anyURI ")]
public string presentity;
}
parlayx标准中对该方法的描述如下:
8.3.4.1 Input message: getMyWatchersRequest
Part name presentity
Part type xsd:anyURI
8.3.4.2 Output message: getMyWatchersResponse
Part name Result
Part type xsd:anyURI [0..unbounded]
wsdl中的信息
<xsd:element name="getMyWatchers" type="presence_supplier_local_xsd:getMyWatchers"/>
<xsd:complexType name="getMyWatchers">
<xsd:sequence>
<xsd:element name="presentity" type="xsd:anyURI"/>
</xsd:sequence>
</xsd:complexType> ---------------------------------------------------part2没有问题的例子
该标准的另外一个接口的wsdl用同样方法部署webservice客户端则没有问题,
下面是这个成功的webservice的信息
============代理类中的相关代码:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( " ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute( "statusEndResponse ", Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")]
public statusEndResponse statusEnd([System.Xml.Serialization.XmlElementAttribute( "statusEnd ", Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")] statusEnd statusEnd1) {
object[] results = this.Invoke( "statusEnd ", new object[] {
statusEnd1});
return ((statusEndResponse)(results[0]));
}
/// <res/ >
public System.IAsyncResult BeginstatusEnd(statusEnd statusEnd1, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke( "statusEnd ", new object[] {
statusEnd1}, callback, asyncState);
}
/// <res/ >
public statusEndResponse EndstatusEnd(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((statusEndResponse)(results[0]));
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")]
public class statusEndResponse {
}
==============客户端中的代码
statusEnd x_object =new statusEnd();
x_object.correlator=textBox1.Text ;
PresenceNotificationService pn=new PresenceNotificationService();
pn.statusEnd (x_object);
=========parlayx标准中对该方法的描述
8.2.2.1 Input message: statusEndRequest
Part name Correlator
Part type xsd:string
8.2.2.2 Output message: statusEndResponse
Part name None
Part type
-----------------------------------------------------------------part3修改后出现的新问题我后来把wsdl和生成的代理文件稍微作了点修改,现在已经可以发送消息了,服务器端也能成功返回response消息,但是出现:未将对象引用设置到对象的实例的错误,相关代码如下:
===wsdl相关内容
<xsd:element name="getMyWatchersResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result" type="xsd:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
======代理文件相关代码
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
public string[] getMyWatchers([System.Xml.Serialization.XmlElementAttribute("getMyWatchers", Namespace="http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local")] getMyWatchers getMyWatchers1) {
object[] results = this.Invoke("getMyWatchers", new object[] {
getMyWatchers1});
return ((string[])(results[0]));
}
=====客户端相关代码
getMyWatchers y_object=new getMyWatchers ();
y_object.presentity="sip:[email protected]:50611";
try
{
PresenceSupplierService ps=new PresenceSupplierService();
string[] result=ps.getMyWatchers (y_object);
label2.Text ="okay";
label2.Text =result.Length.ToString(); //这步会提示未将对象引用设置到对象的实例对比其他成功的webservice实例,我对wsdl和代理文件作了一定修改(修改前的可以在part1中看到)
----------------------------------------------------part0出现问题
错误提示:
未处理的“System.InvalidOperationException”类型的异常出现在 system.web.services.dll 中。
其他信息: 无法反射方法 PresenceSupplierService.getMyWatchers。
==============================
使用呈现的wsdl生成了PresenceSupplierService.dll,并连同System.Web.Services.dll一起添加到项目的引用中,相关代码:
getMyWatchers y_object= new getMyWatchers();
y_object.presentity="sip:[email protected]:50611";
PresenceSupplierService ps=new PresenceSupplierService();//提示出错的是这步
string[] result=ps.getMyWatchers (y_object);
==============================
当我用类似方法调用PresenceNotificationService时是正常的(该service是sag上行到sp侧的,而supplierservice是sp侧下行的sag的);----------------------------------------------------part1相关信息
生成的代理类肯定有问题,我是根据parlay标准的wsdl文件生成的代理类,代理类的源码和测试程序的项目源码都可以提供,感兴趣的话可以留个邮箱给我,另外我的msn:[email protected],可以在线讨论,再回到这里来总结,下面是代理类中getMywatchers方法部分的源码(有点乱,用ultraedit打开好了):
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( " ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlArrayAttribute( "getMyWatchersResponse ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")]
[return: System.Xml.Serialization.XmlArrayItemAttribute( "result ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ", DataType= "anyURI ", IsNullable=false)]
public string[] getMyWatchers([System.Xml.Serialization.XmlElementAttribute( "getMyWatchers ", Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")] getMyWatchers getMyWatchers1) {
object[] results = this.Invoke( "getMyWatchers ", new object[] {
getMyWatchers1});
return ((string[])(results[0]));
}
/// <res/ >
public System.IAsyncResult BegingetMyWatchers(getMyWatchers getMyWatchers1, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke( "getMyWatchers ", new object[] {
getMyWatchers1}, callback, asyncState);
}
/// <res/ >
public string[] EndgetMyWatchers(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((string[])(results[0]));
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace= "http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local ")]
public class getMyWatchers {
/// <res/ >
[System.Xml.Serialization.XmlElementAttribute(DataType= "anyURI ")]
public string presentity;
}
parlayx标准中对该方法的描述如下:
8.3.4.1 Input message: getMyWatchersRequest
Part name presentity
Part type xsd:anyURI
8.3.4.2 Output message: getMyWatchersResponse
Part name Result
Part type xsd:anyURI [0..unbounded]
wsdl中的信息
<xsd:element name="getMyWatchers" type="presence_supplier_local_xsd:getMyWatchers"/>
<xsd:complexType name="getMyWatchers">
<xsd:sequence>
<xsd:element name="presentity" type="xsd:anyURI"/>
</xsd:sequence>
</xsd:complexType> ---------------------------------------------------part2没有问题的例子
该标准的另外一个接口的wsdl用同样方法部署webservice客户端则没有问题,
下面是这个成功的webservice的信息
============代理类中的相关代码:
[System.Web.Services.Protocols.SoapDocumentMethodAttribute( " ", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlElementAttribute( "statusEndResponse ", Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")]
public statusEndResponse statusEnd([System.Xml.Serialization.XmlElementAttribute( "statusEnd ", Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")] statusEnd statusEnd1) {
object[] results = this.Invoke( "statusEnd ", new object[] {
statusEnd1});
return ((statusEndResponse)(results[0]));
}
/// <res/ >
public System.IAsyncResult BeginstatusEnd(statusEnd statusEnd1, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke( "statusEnd ", new object[] {
statusEnd1}, callback, asyncState);
}
/// <res/ >
public statusEndResponse EndstatusEnd(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((statusEndResponse)(results[0]));
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace= "http://www.csapi.org/schema/parlayx/presence/notification/v3_1/local ")]
public class statusEndResponse {
}
==============客户端中的代码
statusEnd x_object =new statusEnd();
x_object.correlator=textBox1.Text ;
PresenceNotificationService pn=new PresenceNotificationService();
pn.statusEnd (x_object);
=========parlayx标准中对该方法的描述
8.2.2.1 Input message: statusEndRequest
Part name Correlator
Part type xsd:string
8.2.2.2 Output message: statusEndResponse
Part name None
Part type
-----------------------------------------------------------------part3修改后出现的新问题我后来把wsdl和生成的代理文件稍微作了点修改,现在已经可以发送消息了,服务器端也能成功返回response消息,但是出现:未将对象引用设置到对象的实例的错误,相关代码如下:
===wsdl相关内容
<xsd:element name="getMyWatchersResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="result" type="xsd:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
======代理文件相关代码
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]
public string[] getMyWatchers([System.Xml.Serialization.XmlElementAttribute("getMyWatchers", Namespace="http://www.csapi.org/schema/parlayx/presence/supplier/v3_1/local")] getMyWatchers getMyWatchers1) {
object[] results = this.Invoke("getMyWatchers", new object[] {
getMyWatchers1});
return ((string[])(results[0]));
}
=====客户端相关代码
getMyWatchers y_object=new getMyWatchers ();
y_object.presentity="sip:[email protected]:50611";
try
{
PresenceSupplierService ps=new PresenceSupplierService();
string[] result=ps.getMyWatchers (y_object);
label2.Text ="okay";
label2.Text =result.Length.ToString(); //这步会提示未将对象引用设置到对象的实例对比其他成功的webservice实例,我对wsdl和代理文件作了一定修改(修改前的可以在part1中看到)
这是因为你的Result为Null,也就是ps.getMyWatchers (y_object);返回了空..
to snowlover: 说的没错,result的确是null,可不明白为什么会是这样啊……
to 孤独的流浪: getwatcher这个方法具体是在服务器侧实现的,客户端是根据wsdl生成的代理调用接口,将方法和参数构造到soap消息发送到服务器侧,服务器同样将响应结果以soap的形式发送回来,从抓到的消息来看,底层的消息交互是没有问题的,客户端可以收到返回的值,但是为什么会出现空引用呢,百思不得其解啊,是不是与我在代理注释掉的那两句return语句有关系呢,可是这两句的确有问题,如果不作修改,甚至无法发送消息出去呢~