silverlight正在调用WCF服务,但未传递参数

本文关键字:参数 服务 调用 WCF silverlight | 更新日期: 2024-10-24 05:41:46

我在一个项目中有一个WCF服务,具有以下设置

//接口

namespace AttendanceSystem
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void DoWork(string s);
    }
}

//以及以下实现

namespace AttendanceSystem
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class Service1 : IService1
    {
        public void DoWork(string s)
        {
            StreamWriter file = new StreamWriter(@"C:'users'waqasjafri'desktop'test.txt");
            if (s == null)
            {
                file.WriteLine("value is null");
            }
            else
            {
                file.WriteLine("value is not null");
            }
            file.Close();
        }
    }
}

以下是我的解决方案中与wcf服务相关的网站应用程序部分中的web.config文件

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

和silverlight项目中的ServiceReference.clientconfig文件

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:48886/Service1.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
            name="BasicHttpBinding_IService1" />
    </client>
</system.serviceModel>

//这是呼叫代码。。。它是在点击按钮触发的事件中

ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
obj.DoWorkAsync("Test");

参数始终以null形式传递。出了什么问题?我想不通,因为我是集成WCF/silverlight/Asp.net的新手。

silverlight正在调用WCF服务,但未传递参数

再次更新您的服务引用。试着这样,在silverlight中,你的方法应该有一个完整的事件,

  ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            client.DoWorkCompleted += (a, ae) =>
            { 
            };
            client.DoWorkAsync("Test");

您可能超过了maxStringContentLength,默认值为8192。请参阅此处:

http://msdn.microsoft.com/en-us/library/ms731361(v=vs.110).aspx

http://msdn.microsoft.com/en-us/library/ms731325(v=vs.110).aspx

您可能还需要考虑使用二进制消息编码。