简体   繁体   English

WCF根目录(/)中的自托管肥皂服务

[英]WCF Self hosting soap-service at root (/) directory

I have device (charger) which sends SOAP-messages to an IP I where I will receive status reports but it is always sent in the root directory and is not changeable: http://192.168.1.2/ 我有一个将SOAP消息发送到IP I的设备(充电器),我将在其中接收状态报告,但它始终在根目录中发送,并且不可更改: http://192.168.1.2/ : http://192.168.1.2/

I made a WCF service self hosted which I want to receive those messages. 我将WCF服务设置为自托管,希望接收这些消息。 But I can not find any information about url-rewriting or listening to something else than the name of the service, in my case it becomes http://192.168.1.2/ocpp15 但是我找不到有关url重写或监听服务名称以外的任何信息,在我的情况下,它变为http://192.168.1.2/ocpp15

Is it possible to rewrite/route from / to /ocpp15/ or from /ocpp15/ to / in any way? 是否可以通过任何方式从/到/ ocpp15 /或从/ ocpp15 /到/重写/路由?

Hosting in a Windows service 托管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();

Service contact 服务联络人

Generated from a WSDL-file with /sc option 从带有/ 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.....

Service 服务

public class Ocpp15 : IOcpp15
{
    public AuthorizeResponse Authorize(AuthorizeRequest request)
    {
        return new AuthorizeResponse { idTagInfo = ValidateRequest(request) };
    }
    and so on.....

I have not found any solution to this in WCF but a hack using Fiddler. 我没有在WCF中找到任何解决方案,而是使用Fiddler的黑客。 Set fiddler to listen on port 80 and accept external requests. 将提琴手设置为侦听端口80并接受外部请求。 Listen to WCF on another port, in my case 8081. 在另一个端口上收听WCF,在我的情况下为8081。

Add this filter to OnBeforeRequest: 将此过滤器添加到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);
     }
}

That last body-replace is for the soap To field which is used sometimes. 最后一个替换的位置是有时使用的To To字段。

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

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