一个webservice使用的问题

zfb312 2010-06-22 11:03:29
我现在在搞一个跨系统工作流,至少包括3个系统,假设为a,b,c 3个系统。
由于系统设计原因,由b系统负责与a,c2个系统交互,而a,c2个系统不能直接交互。
我是这样做的,在每个系统上都有一个webservice方法,当a向b提交数据的时候,需要b同时向c提交数据,
并且需要同时成功,要么就同时失败。
请问各位大侠,有没有webservice控制事务的方法,或者解决思路。
...全文
140 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zfb312 2010-06-24
  • 打赏
  • 举报
回复
还没有解决方案。。谢谢各位了
leonwan 2010-06-24
  • 打赏
  • 举报
回复
/// <summary>
/// 动态调用web服务
///
/// 调用示例
/// string url = "http://www.webservicex.net/globalweather.asmx";
/// string[] args = new string[2];
/// args[0] = "shenzhen";
/// args[1] = "China";
/// object result = WebServiceHelper.InvokeWebService(url ,"GetWeather" ,args);
/// this.label_Result.Text = result.ToString();
/// </summary>
/// <param name="url"></param>
/// <param name="methodname"></param>
/// <param name="args"></param>
/// <returns></returns>
public static object InvokeWebService(string url, string methodname, object[] args)
{
return WebServiceHelper.InvokeWebService(url, null, methodname, args);
}

public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = WebServiceHelper.GetWsClassName(url);
}

try
{
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);

//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();

//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");

//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}

//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);

return mi.Invoke(obj, args);
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}

private static string GetWsClassName(string wsUrl)
{
string[] parts = wsUrl.Split('/');
string[] pps = parts[parts.Length - 1].Split('.');

return pps[0];
}
#endregion

public static string GetRealUrl(string pUrl)
{
string appPath = "/";
if (HttpContext.Current.Request.ApplicationPath != appPath)
{
appPath = HttpContext.Current.Request.ApplicationPath + appPath;
}
string bootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority;
if (!string.IsNullOrEmpty(pUrl) && pUrl.Substring(0, 1) == "/")
{
pUrl = pUrl.Substring(1);
}
string fullUrl = bootUrl + appPath + pUrl;
return fullUrl;
}
-深白色- 2010-06-23
  • 打赏
  • 举报
回复
这个恐怕得楼主自己在b上控制了,比如,a向b提交数据的时候,b先向c提交c写入成功后,b再写入,如果b,c都写入成功,则成功返回,如果有一个不成功,则回滚。这个回滚,得要c接口支持,比如:
c写入成功,b写入失败,则b要向c接口请求删除数据。删除后。b返回给a失败的结果,让a再次尝试。

不过这样还是有个问题,就是b向c接口请求删除数据,这个请求也可能失败。。。。。。。,这个要看楼主的程序是不是能容忍这样的失败。
lester19872007 2010-06-22
  • 打赏
  • 举报
回复
     /// <summary>
/// 动态调用web服务
///
/// 调用示例
/// string url = "http://www.webservicex.net/globalweather.asmx";
/// string[] args = new string[2];
/// args[0] = "shenzhen";
/// args[1] = "China";
/// object result = WebServiceHelper.InvokeWebService(url ,"GetWeather" ,args);
/// this.label_Result.Text = result.ToString();
/// </summary>
/// <param name="url"></param>
/// <param name="methodname"></param>
/// <param name="args"></param>
/// <returns></returns>
public static object InvokeWebService(string url, string methodname, object[] args)
{
return WebServiceHelper.InvokeWebService(url, null, methodname, args);
}

public static object InvokeWebService(string url, string classname, string methodname, object[] args)
{
string @namespace = "EnterpriseServerBase.WebService.DynamicWebCalling";
if ((classname == null) || (classname == ""))
{
classname = WebServiceHelper.GetWsClassName(url);
}

try
{
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);

//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(cn);
sdi.Import(cn, ccu);
CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler();

//设定编译参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");

//编译代理类
CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
if (true == cr.Errors.HasErrors)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
{
sb.Append(ce.ToString());
sb.Append(System.Environment.NewLine);
}
throw new Exception(sb.ToString());
}

//生成代理实例,并调用方法
System.Reflection.Assembly assembly = cr.CompiledAssembly;
Type t = assembly.GetType(@namespace + "." + classname, true, true);
object obj = Activator.CreateInstance(t);
System.Reflection.MethodInfo mi = t.GetMethod(methodname);

return mi.Invoke(obj, args);
}
catch (Exception ex)
{
throw new Exception(ex.InnerException.Message, new Exception(ex.InnerException.StackTrace));
}
}

private static string GetWsClassName(string wsUrl)
{
string[] parts = wsUrl.Split('/');
string[] pps = parts[parts.Length - 1].Split('.');

return pps[0];
}
#endregion

public static string GetRealUrl(string pUrl)
{
string appPath = "/";
if (HttpContext.Current.Request.ApplicationPath != appPath)
{
appPath = HttpContext.Current.Request.ApplicationPath + appPath;
}
string bootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority;
if (!string.IsNullOrEmpty(pUrl) && pUrl.Substring(0, 1) == "/")
{
pUrl = pUrl.Substring(1);
}
string fullUrl = bootUrl + appPath + pUrl;
return fullUrl;
}

动态调用 WS。。。
-小蕾- 2010-06-22
  • 打赏
  • 举报
回复
Webservice控制事务没做过,帮顶,想学习。。。
zfb312 2010-06-22
  • 打赏
  • 举报
回复
分布式事务不支持webservice。。。
leonwan 2010-06-22
  • 打赏
  • 举报
回复
在a向b提交数据的时候就做控制,如果有错误就回滚,不做b向c提交数据的操作
leonwan 2010-06-22
  • 打赏
  • 举报
回复
用分布式事务处理能行吗?

zfb312 2010-06-22
  • 打赏
  • 举报
回复
自己顶一下,沉了。。
bojiansky 2010-06-22
  • 打赏
  • 举报
回复
帮顶,学习下!
MMYY19668804MY521 2010-06-22
  • 打赏
  • 举报
回复
帮顶,学习下

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧