我有一个向IP发送SOAP消息的设备(充电器),我将在那里接收状态报告,但它总是在根目录中发送,并且不可更改:http://192.168.1.2/
我做了一个WCF服务自托管,我想要接收这些消息。但是我找不到任何关于url重写或侦听服务名称以外的信息,在我的例子中,它变成了http://192.168.1.2/ocpp15
是否可以以任何方式重写/路由自/到/ocpp15/或从/ocpp15/到/?
在Windows服务中托管
var smb = new ServiceMetadataBehavior
{
HttpGetEnabled = true,
MetadataExporter = { PolicyVersion = PolicyVersion.Policy12 },
};
var serviceDebugBehavior = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true };
var baseAddress15 = new Uri(String.Format("http://{0}/, Environment.MachineName));
var host15 = new ServiceHost(typeof(Ocpp15), baseAddress15);
host15.Description.Behaviors.Add(smb);
host15.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
host15.Description.Behaviors.Add(serviceDebugBehavior);
host15.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
host15.AddServiceEndpoint(typeof(IOcpp15), new WSHttpBinding(SecurityMode.None), "");
host15.Open();服务联系人
使用/sc选项从WSDL文件生成
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "urn://Ocpp/Cs/2012/06/", ConfigurationName = "Ocpp15")]
public interface IOcpp15
{
// CODEGEN: Generating message contract since the wrapper name (authorizeRequest) of message AuthorizeRequest does not match the default value (Authorize)
[System.ServiceModel.OperationContractAttribute(Action = "/Authorize", ReplyAction = "/AuthorizeResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
AuthorizeResponse Authorize(AuthorizeRequest request);
and so on.....服务
public class Ocpp15 : IOcpp15
{
public AuthorizeResponse Authorize(AuthorizeRequest request)
{
return new AuthorizeResponse { idTagInfo = ValidateRequest(request) };
}
and so on.....发布于 2014-03-07 07:06:12
我没有在WCF中找到任何解决方案,除了使用Fiddler的黑客攻击。将fiddler设置为侦听端口80并接受外部请求。在另一个端口上侦听WCF,在我的例子中是8081。
将此筛选器添加到OnBeforeRequest:
if (oSession.host.toLowerCase() == "192.168.1.2" || oSession.host.toLowerCase() == "192.168.1.2:80")
{
oSession.host = "192.168.1.2:8081";
if (oSession.PathAndQuery=="/")
{
oSession.PathAndQuery="/ocpp15/";
var strBody1 = oSession.GetRequestBodyAsString ();
strBody1 = strBody1.replace("http://172.28.0.30/","http://172.28.0.30:8081/ocpp15/");
oSession.utilSetRequestBody (strBody1);
}
}最后一个主体替换是用于soap To字段,该字段有时会被使用。
https://stackoverflow.com/questions/22097571
复制相似问题