zoukankan      html  css  js  c++  java
  • WCF Part 4 : Make your service visible through metadata

    Last time we saw how we could create an instance of our service by hosting it using some configuration in our app.config. We still need to have it exposed using metadata though. We'll do this by adding an endpoint that exposed this, using our WCF ABC again. This endpoint is called a MEX endpoint, from Metadata EXchange.

    For this we don't have to create any code, just configuration again. Open the Service Configuration Editor again on our app.config. Open the folder "Advanced", then "Service Behaviors" and choose to add a new service behavior. We'll change the name NewBehavior to HelloServiceBehavior. Now click the Add button and select the 'ServiceMetadata' option.

     

    Now we'll configure our new behavior in and endpoint. Select your service again in the tree. This is something you'll probably forget a lot in the future, but you'll have to bind the just configured behavior to your service. You should be able to select it from the list in the BehaviorConfiguration property on your service.

    Now let's actually add our MEX endpoint. Select the "Endpoints" folder under our service and right-click it, then choose to add a new endpoint. Set the address to http://localhost:8080/HelloService/MEX/, select for binding the "mexHttpBinding" and for contract fill in "IMetadataExchange". Now save, exit the configuration editor and you should have the following configuration.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
     
        <system.serviceModel>
            <behaviors>
                <serviceBehaviors>
                    <behavior name="HelloServiceBehavior">
                        <serviceMetadata />
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <services>
                <service behaviorConfiguration="HelloServiceBehavior" name="Classa.Wcf.Samples.Hello">
                    <endpoint address="http://localhost:8080/HelloService/" binding="basicHttpBinding"
                        bindingConfiguration="" contract="Classa.Wcf.Samples.IHello" />
                    <endpoint address="http://localhost:8080/HelloService/MEX/" binding="mexHttpBinding" bindingConfiguration=""
                        contract="IMetadataExchange" />
                </service>
            </services>
        </system.serviceModel>
    </configuration>

    Run your service with F5. You'll notice no difference, but now you can create a proxy with the service util. Open the Visual Studio Command Prompt (in your start menu under Visual Studio 2005/Visual Studio Tools) and execute the following command:

    svcutil.exe /o:client.cs /config:app.config http://localhost:8080/HelloService/MEX/

    If you're interested, take a look at the generated files. Especially the generated app.config, which should contain an ABC reference to your service. 

  • 相关阅读:
    数据结构考研--线性表例2-4
    2011 BENELLI TRE1130K所有系统诊断:OBDSTAR MS80或OBDSTAR MS50?
    BMW E60可以通过Autel IM508和XP400 Pro读取数据并学习密钥吗?
    Launch X431 V V4.0 2021最新升级:32GB存储+ 30特殊功能
    Autel IM608 Pro为BMW 2010 535i添加新钥匙
    Xhorse VVDI Prog V5.0.0软件免费下载
    使用XP400 Pro通过Autel IM508读取Benz W207 EIS数据
    由CGDI Prog BMW与GODIAG GT100进行的BMW FEM / BDC密钥编程
    BMW CAS4 / CAS4 +编程测试平台购买建议
    2021 GODIAG GT100 ECU接线盒评测:出色的诊断和节省维修成本的设备
  • 原文地址:https://www.cnblogs.com/malaikuangren/p/2552064.html
Copyright © 2011-2022 走看看