WebService端口号修改
来源:互联网 发布:基础设施网络建设 编辑:程序博客网 时间:2024/06/06 02:17
C#中使用webservice接口的时候,返给服务器的IP地址是带上了端口号的。但是有时候不能要那个端口(比如用nginx做了转发),就需要在服务端处理一下(处理内容就是后面的代码)。此外,需要在配置文件中web.config中的system.web中添加一些东西:
<webServices>
<protocols>
<addname="HttpGet"/>
<addname="HttpPost"/>
<addname="HttpSoap"/>
</protocols>
<soapExtensionReflectorTypes>
<addtype="CommMethod.OuterPortReflector,CommMethod"/>
</soapExtensionReflectorTypes>
</webServices>
注:1.type内容是类名,包名。这一点和msdn上的那个人写的有些不同(有可能是版本的问题)(http://blogs.msdn.com/b/kaevans/archive/2005/11/16/493496.aspx)。
2.如果没有protocols中的内容的话,有可能post和get请求不能被正确识别(未做过验证,只是在博客园上看见过类似问题)。
3.stackoverflow源地址:http://stackoverflow.com/questions/1531448/asp-net-web-service-changes-port-on-invoke
代码:
//-----------------------------------------------------------------------
// <copyright file="OuterPortReflector.cs" company="">
// * Copyright (C)
// * version :
// * author : ying83811
// * FileName: OuterPortReflector.cs
// * history : created by ying83811
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Services.Description;
namespace Better517Na.KoreaProductInterface.CommMethod
{
/// <summary>
/// OuterPortReflector类
/// </summary>
public class OuterPortReflector : SoapExtensionReflector
{
/// <summary>
/// 重写ReflectMethod
/// </summary>
public override void ReflectMethod()
{
}
/// <summary>
/// 重写ReflectDescription
/// </summary>
public override void ReflectDescription()
{
// 为了说明问题,这里直接把端口号写死了,建议写在配置文件中
string portNum = "8888";
portNum = ":" + portNum;
ServiceDescription description = ReflectionContext.ServiceDescription;
foreach (Service service in description.Services)
{
foreach (Port port in service.Ports)
{
foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
{
SoapAddressBinding binding = extension as SoapAddressBinding;
if (null != binding)
{
binding.Location = binding.Location.Replace(portNum, string.Empty);
}
else
{
HttpAddressBinding httpBinding = extension as HttpAddressBinding;
if (httpBinding != null)
{
httpBinding.Location = httpBinding.Location.Replace(portNum, string.Empty);
}
else
{
Soap12AddressBinding soap12Binding = extension as Soap12AddressBinding;
if (soap12Binding != null)
{
soap12Binding.Location = soap12Binding.Location.Replace(portNum, string.Empty);
}
}
}
}
}
}
}
}
}
- WebService端口号修改
- 修改Tomcat端口号
- 修改Tomcat端口号
- 修改远程桌面端口号
- 修改Tomcat端口号
- Tomcat端口号修改
- Jboss修改端口号
- JBOSS端口号修改
- 修改Tomcat端口号
- 修改tomcat端口号
- tomcat修改端口号
- 修改端口号
- 修改Weblogic端口号
- 修改TOMCAT端口号
- 修改Tomcat端口号
- 修改Tomcat端口号
- 修改svn端口号
- 修改Tomcat端口号
- iOS 捕获长按事件,跟踪滑动轨迹
- Hibernate4是用二级缓存的步骤
- linux 服务器优化设置
- 指针数组和数组指针的区别
- 单向哈希函数 JAVA版本
- WebService端口号修改
- 通过SpringAOP+注解实现自动代理
- Android 传感器之《加速传感器》——摇一摇功能
- android通过camera和surfaceview选择摄像头并即时预览
- cocos2d-x学习笔记:SpriteBatchNode
- merge 使用与实例3
- Android开源项目第一篇——个性化控件(View)篇
- pci总结
- 五个编程谬论