我想在C#ASP.Net Web应用程序中使用Web服务。该服务使用PHP构建,位于某些远不在我控制范围内的远程服务器上,因此无法修改它以添加元数据或其他内容。如何从ASP.Net访问PHP Web服务?
当我使用Visual Studio 2008中, “添加Web引用”选项,我收到以下错误:
The HTML document does not contain Web service discovery information.
试图添加下面的Web服务。
https://subreg.forpsi.com/robot2/subreg_command.php?wsdl
该网站的服务功能进行曝光,但是我不能引用添加到它在ASP.Net应用程序使用Visual Studio 2008中显示。
t3Service" Description
Methods __construct ()
create_contact ()
get_contact ()
get_domain_info ()
get_last_error_code ()
get_last_error_msg ()
get_NSSET ()
get_owner_mail ()
login ()
register_domain ()
register_domain_with_admin_contacts ( )
renew_domain ()
request_sendmail ()
send_auth_info ()
transfer_domain ()
我还通过检索XML并将其复制到WSDL文件并生成代理类试过Wsdl.exe用方法。但wsdl输出包含警告,并且生成的代理类跳过了公开的函数并生成如下所示的内容:
// CODEGEN:忽略命名空间'urn:t3'中绑定'create_contact'的操作。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:忽略命名空间'urn:t3'中绑定'get_contact'的操作。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'get_domain_info'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'get_last_error_code'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:忽略命名空间'urn:t3'中绑定'get_last_error_msg'的操作。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'get_NSSET'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:忽略命名空间'urn:t3'中绑定'get_owner_mail'的操作。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'send_auth_info'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'transfer_domain'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'request_sendmail'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:忽略命名空间'urn:t3'的操作绑定'login'。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:忽略命名空间'urn:t3'的操作绑定'register_domain'。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'register_domain_with_admin_contacts'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。 // CODEGEN:从命名空间'urn:t3'绑定'renew_domain'的操作被忽略。 use = encoded消息中的每个消息部分都必须指定一个类型。
编辑:
我想这段代码为我的手编码的一类。
public String makeWebRequest(String methodName)
{
// Create the web request
HttpWebRequest request = WebRequest.Create("https://subreg.forpsi.com/robot2/subreg_command.php/") as HttpWebRequest;
// Add authentication to request
request.Credentials = new NetworkCredential("[email protected]", "bar");
request.Method = "POST";
request.ContentType = "text/xml";
request.Headers.Add("SOAPAction: https://subreg.forpsi.com/robot2/subreg_command.php/" + methodName);
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Console application output
//Console.WriteLine(reader.ReadToEnd());
return reader.ReadToEnd();
}
}
但是,当我试图让响应,那么它将返回
The remote server returned an error: (500) Internal Server Error.
@Dan非常感谢这段代码。它真的清除了我对这个问题的看法。 你的代码中的每一件事都是可以理解的。但我无法得到/找到名为* GetSoapString *的函数。你可以请告诉它做了什么,这样我可以写我自己的一个,或者如果它已经定义,那么你可以给它的实现或.Net命名空间conatins的定义? – 2010-03-19 03:57:08
@丹 我没有尝试你的代码。但试图从服务器获得响应时,我收到以下内容: *远程服务器返回了错误:(500)内部服务器错误。* 这是正常吗?如果是,那么我需要在我的代码中处理这样的响应。 在发布我的问题在stackoverflow之前,我尝试了一些其他的代码,并试图发送一个Web请求,但同样的错误返回。 这是否意味着它需要一些授权或凭证?我清楚地看到一个Login()函数吗?这是造成问题的SSL吗?如果我要将凭据发送到Web服务如何发送它们? – 2010-03-19 04:10:15
@Dan * WebResponse webResponse = httpRequest.GetResponse(); * 这是上述错误返回的行。 – 2010-03-19 04:10:57