【问题标题】:WCF service using mod_mono使用 mod_mono 的 WCF 服务
【发布时间】:2012-01-26 15:46:02
【问题描述】:

我正在尝试使用 mono 2.10.8 在 CentOS 上托管 WCF 服务,并将其作为 REST 或 SOAP 服务器访问。

我在包含我的 web.config 的文件夹中使用 mod-mono-server-4 启动了一个应用程序:

<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="WebBehavior" name="Services.Hello">
                <clear/>
                <endpoint address="http://DOMAIN/service" behaviorConfiguration="HelloBehavior" binding="webHttpBinding" contract="Services.IHello" />
                <endpoint address="http://DOMAIN/web" binding="basicHttpBinding" bindingConfiguration="" contract="Services.IHello" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="HelloBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="WebBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

如果我现在调用DOMAIN/web?wsdlDOMAIN/service/hello/hello 是 IHello 中方法的 WebGetAttribute 的 UriTemplate),我只会得到 404:

“/”应用程序中的服务器错误
找不到资源。

我还有一个Service.svc 文件,其中包含:

如果我打电话给DOMAIN/Service.svc/hello,我会收到一个 SOAP 错误:

请求消息的目标为“http://DOMAIN/Service.svc/hello”,操作为“”,在此服务合同中无法访问

如果我在执行以下操作的服务器上启动控制台应用程序:

WebServiceHost sh = new WebServiceHost(typeof(Hello), new Uri("http://localhost:681/service"));
sh.Open();

我可以访问端口 680 上的服务,因此 mono 应该能够运行该服务,但我需要它与 mod_mono 一起运行(在端口 80 上)。

我需要进行哪些不同的配置?

最后,我尝试托管 SyndicationFeed 来提供 RSS/Atom-Feed。

【问题讨论】:

    标签: c# .net wcf mono mod-mono


    【解决方案1】:

    我找到了让它运行 ATM 的解决方法:
    创建一个普通的 *.asmx-WebService 并创建一个类似的方法:

    [WebMethod]
    [SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
    public XmlDocument Feed()
    {
        SyndicationFeed feed = new SyndicationFeed();
        //Fill the feed...
        Atom10FeedFormatter atom = new Atom10FeedFormatter(feed);
    
        StringBuilder result = new StringBuilder();
        XmlWriter writer = XmlWriter.Create(result);
        atom.WriteTo(writer);
        writer.Flush();
    
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(result.ToString());
    
        return doc;
    }
    

    然后您可以通过DOMAIN/Service.asmx/Feed 访问提要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 2013-04-11
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多