简体   繁体   English

c#SOAP客户端到具有多个名称空间的PHP webservice

[英]c# SOAP client to PHP webservice with multiple namespaces

We are building application which communicates with another application via soap web services. 我们正在构建通过soap Web服务与另一个应用程序通信的应用程序。 The other application is developed by another company using PHP. 另一个应用程序是由另一家公司使用PHP开发的。 Our app is client to their web service. 我们的应用程序是其Web服务的客户端。

We have testing environment where we connected our apps and everything worked fine. 我们有测试环境,我们连接我们的应用程序,一切正常。 Then we moved to production env. 然后我们转到生产环境。 But their web service namespace is generated automatically based on URL, so namespace in test and prod env are mismatched. 但是他们的Web服务命名空间是基于URL自动生成的,因此test和prod env中的命名空间不匹配。

I generated SOAP client with svcutil once more for production, but when I deploy my solution to test env, I can't connect to their web service. 我再次使用svcutil生成SOAP客户端用于生产,但是当我将我的解决方案部署到测试环境时,我无法连接到他们的Web服务。 They also are not willing to change anything. 他们也不愿意改变任何事情。

Is it possible to change namespace of web service client during runtime based on endpoint address? 是否可以在运行时根据端点地址更改Web服务客户端的命名空间?

As far as I know, you can't change the namespace at runtime. 据我所知,您无法在运行时更改命名空间。 The obvious option that would definitely work would probably be to do it at compile time, something like; 绝对可行的明显选择可能是在编译时完成它,例如;

#if PRODUCTION
[ServiceContract(Namespace = "MyProduction Namespace", Name = "PhpServiceContract")]
#else
[ServiceContract(Namespace = "MyTest Namespace", Name = "PhpServiceContract")]
#endif

If you're using it in multiple places and don't want to #if everywhere, just move it to a constant; 如果你在多个地方使用它并且不想在任何地方#if ,只需将它移动到一个常数;

[ServiceContract(Namespace=Definitions.CURRENT_NAMESPACE, Name = "PhpServiceContract")]

and then just define it in one place; 然后在一个地方定义它;

public static class Definitions
{
#if PRODUCTION
    public const string CURRENT_NAMESPACE = "MyProduction Namespace";
#else
    public const string CURRENT_NAMESPACE = "MyTest Namespace";
#endif
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM