点出来了的,说是无法加载协定为“ServiceReference.Service1Soap”的终结点配置 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Wclient { public partial class Form1 : Form { private ServiceReference.Service1SoapClient Client; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Client = new ServiceReference.Service1SoapClient(); string name = Client.showtime(); textBox1.Text=name; } } }
或者用ajax调用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace Wclient
{
public partial class Form1 : Form
{
private ServiceReference.Service1SoapClient Client;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
Client = new ServiceReference.Service1SoapClient();
string name = Client.showtime();
textBox1.Text=name;
}
}
}
接着就实例化webservice,实例名。具体的方法....完毕..........
调用代码如下: private void button1_Click(object sender, EventArgs e)
{
new localhost.Service1().HelloWorld();
}
你的客户端加App.config了吗?
Web引用名.命名空间.类名 cc=new Web引用名.命名空间.类名(参数)
cc.方法(参数)
看下你写的webservice共享没有(每个方法前面加上 [*******])具体的什么忘记了
<client>
<endpoint address="http://localhost/WcfWebService/WcfServiceLibrary/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService11"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService11">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>看你的App.Config中这个Client结点下..有几个endpoint.
看你的提示..不只一个..
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Service1Soap" 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="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="Service1Soap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/Service1.asmx" binding="basicHttpBinding"
bindingConfiguration="Service1Soap" contract="ServiceReference.Service1Soap"
name="Service1Soap" />
<endpoint address="http://localhost:8000/Service1.asmx" binding="customBinding"
bindingConfiguration="Service1Soap12" contract="ServiceReference.Service1Soap"
name="Service1Soap12" />
</client>
</system.serviceModel>
</configuration>
<endpoint address="http://localhost:8000/Service1.asmx" binding="basicHttpBinding"
bindingConfiguration="Service1Soap" contract="ServiceReference.Service1Soap"
name="Service1Soap" />
<endpoint address="http://localhost:8000/Service1.asmx" binding="customBinding"
bindingConfiguration="Service1Soap12" contract="ServiceReference.Service1Soap"
name="Service1Soap12" />
</client>
这两个<endpoint>都有用吗?
是引用的时候自动生成的吗?你可以先把里面的内容清空..再重新引用一下..看行不
<endpoint address="http://localhost:8000/Service1.asmx" binding="basicHttpBinding"
bindingConfiguration="Service1Soap" contract="ServiceReference.Service1Soap"
name="Service1Soap" />
<endpoint address="http://localhost:8000/Service1.asmx" binding="customBinding"
bindingConfiguration="Service1Soap12" contract="ServiceReference.Service1Soap"
name="Service1Soap12" />
</client>
把上面的endpoint删除..只留下面那个..应该有一个是不正确的..
不行.就把下面的删除..留上面的..
试试下面的方法
<client>
<endpoint address="http://localhost:8000/Service1.asmx" binding="basicHttpBinding"
bindingConfiguration="Service1Soap" contract="ServiceReference.Service1Soap"
name="Service1Soap" />
<endpoint address="http://localhost:8000/Service1.asmx" binding="customBinding"
bindingConfiguration="Service1Soap12" contract="ServiceReference.Service1Soap"
name="Service1Soap12" />
</client>
把上面的endpoint删除..只留下面那个..应该有一个是不正确的..
不行.就把下面的删除..留上面的..
不过没事..删除没用的就行.
如果是你删除原来的再引用就没事..
呵..那是引用WEbService生成的代理类里面的东西..不用管他们..