使用参数使用WCF

时间:2013-12-27 14:18:29

标签: c# wcf web-services wcf-rest

我无法使用URL

中的参数来使用WCF

我在WCF中的方法: Login(user,pass)

我的aspx.cs代码:

Service1Client respLogin = new Service1Client().Login(user, pass);

我的web.config:

<system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="AllocationBehavior">
                    <webHttp/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <client>
            <endpoint name="ServiceReference1.IService1"
                      address="http://1.234.567:8/service1.svc"
                      binding="webHttpBinding"
                      behaviorConfiguration="AllocationBehavior"
                      contract="ServiceReference1.IService1" />
        </client>
</system.serviceModel>

错误讯息:There was no endpoint listening at that could accept http://1.234.567:8/service1.svc/Login message

这是正确的,http://1.234.567:8/service1.svc/Login不存在(我需要在URL中添加参数),但http://1.234.567:8/service1.svc/Login/user/pass确实存在且响应正常!!

我无法添加参数user并传入URL ...

我如何添加参数user&amp;使用WCF和C#传递URL?

谢谢啦!!

1 个答案:

答案 0 :(得分:1)

您似乎忘记使用WebGet attribute修饰服务实现。这就是在WCF RESTful服务中指定URL参数的方式。