当前位置:编程学习 > C#/ASP.NET >>

急求!如何用windows service调用部署在IIS上的WCFservice


我需要开发一个windows service,通过此service可以调用已经发布在IIS 上的wcf service, 并且这个wcf service 被部署在与windows service同一个域下的另外一台电脑上。 求救,怎样在windows service中调用这样的wcf service 呢? 我尝试用一般的调用方式,通过在windows service 项目上 点击 增加web service,输入地址,的方式加入wcf service, 不过报错了。

错误:Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
调用WCF service 代码如下:
 ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
                                        client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
                                        client.ClientCredentials.Windows.ClientCredential.Password = "Password1";
                                        client.ClientCredentials.Windows.ClientCredential.Domain = "TMServerA.GES-TM.COM    xmlstring = client.DriverData(sw.ToString(), i);
app.config如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportCredentialOnly">
                        <transport clientCredentialType="Ntlm" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://tmservera/wintest/Service1.svc" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
                name="BasicHttpBinding_IService1" />
        </client>
    </system.serviceModel>
</configuration> --------------------编程问答-------------------- 网上的都是介绍 怎样用windows service 来做WCF 宿主的~
没有介绍 用windows service作客户端的~
求救呀,求救~ --------------------编程问答--------------------
顶起,不能沉呀~ --------------------编程问答-------------------- 还是没人理
不过我想到了一个替代的方法。 
先建一个Console的程序,在这个程序内调用部署在IIS 上的WCF SSERVICE 。
然后再在WINDOWS SERVICE 中通过代码运行这个Console程序的EXE 文件,这样算是间接地调用了WCF SERVICE。
不过还是没有找到直接调用的方法!! --------------------编程问答--------------------
Windows Service 直接通过添加 Service Reference 就能调用WCF了啊。

你的错误是因为WCF Service有错误

看你的错误提示:Could not find default endpoint element that references contract 'ServiceReference1.IService1' 

另外要注意 Windows Service 的权限。
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,