C#创建webservice接口,三方通过多次跳转访问本方服务,获取wsdl文档,wsdl中ip地址为局域网内本机地址而非三方直接访问的地址。请教如何让三方获取的wsdl文档中地址为外网映射IP和端口(浏览器中输入的地址)。
对方启动的服务如下,浏览器中地址端口和文档中一致,没有问题
我方启动的服务如下,仅在本机启动跳转做示例,浏览器中地址端口和文档不一致,出现问题
相关接口程序情况如下:
配置文件:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup><system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="XmHttpServerForm.Service1">
<endpoint address="" binding="basicHttpBinding" contract="XmHttpServerForm.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://10.39.14.141:8002/" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://10.39.14.141:8002/Service1/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
接口:
namespace XmHttpServerForm
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService1”。
[ServiceContract]
public interface IService1
{
// [OperationContract]
// void DoWork();
[OperationContract]
string JSYX(string context);
}
}
实现:
namespace XmHttpServerForm
{
// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“Service1”。
public class Service1 : IService1
{
//public void DoWork()
//{
//}
string m_BankCode = "301000";
string m_UnitCode = "G321282";
string m_AppId = "01";
string m_BankNo = "03";
string m_CheckCode = "";
byte[] key = { 17, 34, 79, 88, 136, 16, 64, 56, 40, 37, 121, 81, 203, 221, 85, 102, 119, 41, 116, 152, 48, 64, 54, 226 };
public string JSYX(string context)
{
string curClassName = "";
return curClassName;
}
}
}
主程序启动服务:
namespace XmHttpServerForm
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
ServiceHost host = new ServiceHost(typeof(Service1));
host.Open();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}