我有个VB的代码如下:
Set SoapClient = CreateObject("MSSOAP.SoapClient30")
'Initialize the SOAP Client object, specifying it's location
Call SoapClient.MSSoapInit("http://" + siteDirector + "/BasicServices.asmx?wsdl", "BasicServices", "BasicServicesSoap") 'Specify the End Point URL in the SOAP Client object
SoapClient.ConnectorProperty("EndPointURL") = "http://" + siteDirector + "/BasicServices.asmx" result = InitMethodAuthentication("ReadProperty", RefNames(i).Text)
If result <> 0 Then Exit For 'Call the ReadProperty web service
On Error Resume Next
result = SoapClient.ReadProperty(RefNames(i).Text, "Present Value", StrValue, Value, Reliability, Priority)里面SoapClient调用WebServices方法ReadProperty 怎么在C#里面怎么调用啊!
这个软件不能用C#自带的WebServices访问。请大神解决下。谢谢。
Set SoapClient = CreateObject("MSSOAP.SoapClient30")
'Initialize the SOAP Client object, specifying it's location
Call SoapClient.MSSoapInit("http://" + siteDirector + "/BasicServices.asmx?wsdl", "BasicServices", "BasicServicesSoap") 'Specify the End Point URL in the SOAP Client object
SoapClient.ConnectorProperty("EndPointURL") = "http://" + siteDirector + "/BasicServices.asmx" result = InitMethodAuthentication("ReadProperty", RefNames(i).Text)
If result <> 0 Then Exit For 'Call the ReadProperty web service
On Error Resume Next
result = SoapClient.ReadProperty(RefNames(i).Text, "Present Value", StrValue, Value, Reliability, Priority)里面SoapClient调用WebServices方法ReadProperty 怎么在C#里面怎么调用啊!
这个软件不能用C#自带的WebServices访问。请大神解决下。谢谢。
你的服务的WSDL不标准么?为什么不能添加web引用?
下面是WebServices Server端引用代码:
/// <res/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System", "1.0.0.0")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="BasicServicesSoap", Namespace="http://abc.com/WebServices/")]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(UserAuthenticationHeader))]
public partial class BasicServices : System.Web.Services.Protocols.SoapHttpClientProtocol {
public EncryptedCertificate EncryptedCertificateValue;
public LoginResult LoginResultValue;
/// <res/>
public BasicServices() {
this.Url = "http://192.168.1.100/BasicServices.asmx";
}
/// <res/>
[System.Web.Services.Protocols.SoapHeaderAttribute("LoginResultValue")]
[System.Web.Services.Protocols.SoapHeaderAttribute("EncryptedCertificateValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://abc.com/WebServices/ReadProperty", RequestNamespace="http://abc.com/WebServices/", ResponseNamespace="http://abc.com/WebServices/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public int ReadProperty(string reference, string property, out string stringValue, out double rawValue, out string reliability, out string priority) {
object[] results = this.Invoke("ReadProperty", new object[] {
reference,
property});
stringValue = ((string)(results[1]));
rawValue = ((double)(results[2]));
reliability = ((string)(results[3]));
priority = ((string)(results[4]));
return ((int)(results[0]));
}
[System.CodeDom.Compiler.GeneratedCodeAttributeSystem", "1.0.0.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://abc.com/WebServices/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://abc.com/WebServices/", IsNullable=false)]
public partial class EncryptedCertificate : System.Web.Services.Protocols.SoapHeader {
/// <res/>
[System.Xml.Serialization.XmlTextAttribute()]
public string[] Text;
}
public partial class UserAuthenticationHeader : System.Web.Services.Protocols.SoapHeader {
/// <res/>
public string UserName;
/// <res/>
public int UserId;
}
public partial class LoginResult : UserAuthenticationHeader {
/// <res/>
public System.Xml.XmlNode securityToken;
}
VB里面是这样验证的,官方给了一个验证的DLL文件.通过SoapClient用如下方法验证
Private Function InitSoapClient(ByVal siteDirector As String) As Boolean
'Create the SOAP Client object that will be used to call the Basic web services
Set SoapClient = CreateObject("MSSOAP.SoapClient30")
On Error Resume Next
'Initialize the SOAP Client object, specifying it's location
Call SoapClient.MSSoapInit("http://" + siteDirector + "/BasicServices.asmx?wsdl", "BasicServices", "BasicServicesSoap")
If Err <> 0 Then
InitSoapClient = False
Else
'Specify the End Point URL in the SOAP Client object
SoapClient.ConnectorProperty("EndPointURL") = "http://" + siteDirector + "/BasicServices.asmx"
'Set the HeaderHandler property. The header handler will be responsible for
'setting up the Soap Header so that subsequent web service calls work.
Set SoapClient.HeaderHandler = Security.HeaderHandler
InitSoapClient = True
End If
其中的Security.HeaderHandler是第三方提供的DLL文件里面通过输入地址,用户名及密码提供的.
用C#的webservices不知道这个头怎么写.请帮忙.谢谢.
你可以尝试设置WebClientProtocol.Credentials