一般的 Web Method 已经通过 sproxy工具成功生成了cpp client 类
测试好使,不过又想到了,发布在局域网的IIS后, 是可以在服务器的本机测试的,
如果用户好奇心很强,动手能力还差不多,那么就容易崩溃了。。。
所以经过搜索,得到了 使用 soap header 的一个方法 来增加一个简单的验证方式。
结果,出现了问题,新建立的 WebService1.asmx.cs 代码如下:
- C# code
using System;using System.Collections.Generic;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;namespace Test1{ [Serializable] public class AuthHeader : SoapHeader { private string _username; private string _password; public string UserID { get { return _username; } set { _username = value; } } public string Password { get { return _password; } set { _password = value; } } } /// <summary> /// WebService1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { public AuthHeader theHeader; [WebMethod] public AuthHeader Dummy() { return null; } [WebMethod(Description = "QueryRuntimeCommand.")] //[SoapHeader("theHeader", Direction = SoapHeaderDirection.In)] public string QueryRuntimeCommand(string TaskWorkingID, out string RuntimeCommand) { string ErrText = "QuerySuccess"; RuntimeCommand = "Start"; if (theHeader == null || theHeader.UserID == null) return "Unauthenticated"; if (theHeader.UserID != "wawa") return "Unauthenticated"; return ErrText; } }}
没有语句 [SoapHeader("theHeader", Direction = SoapHeaderDirection.In)] 的时候很正常。
使用自己编译的sproxy的debug版生成了客户端文件,使用正常。
但是如果加上那条语句,也就是要是用soap header进行通信,sproxy就会崩溃,
(debug 版的一个断言codetypebuilder.cpp 的2547行 pPart != 0),release版的没有崩溃,不过产生的客户端代码的AuthHeader相关定义是空着的。。
以此为基础,又仅把方法名 QueryRuntimeCommand 改成了 QueryRC 结果却是正常的生成了.h文件。。
百思不得其解,不知道原来的名字是不是与sproxy内部产生了冲突?
我用的不是vs2003或者vs2008的sproxy, 是http://atlserver.codeplex.com/ 这里的
不知谁能解惑?或者有一个完善的sproxy.exe?毕竟我不知道还能因为哪些方法名称的字符序列而崩溃。
谢啦~~
------解决方案--------------------
google了下,好像没有解决方案。
------解决方案--------------------
只是禁止从浏览器本地测试的话
可以试试在web.config里配置下:
<webServices>
<protocols>
<remove name="Documentation"/>
</protocols>
</webServices>
另外对vc不熟,如果是.net生成的代理类,应该在代理类文件中包含有soap头的信息
初始化的时候写入就行了
private AuthHeader authHeaderValueField;
/// <remarks/>
public WebService(string sUrl)
{
this.Url = sUrl;// "http://localhost:6487/RCMS973NEW/WebService.asmx"; //sUrl;//
AuthHeader ah = new AuthHeader();
ah.Token = "";// Common.DESEncrypt(DateTime.Now.ToString());
this.AuthHeaderValue = ah;
}
如果是VC6
可以考虑微软之前的工具SoapToolkit
里面有对soap头的支持 但是我没测试过不清楚调用.net的情况