调用WCF客户端时的keyNotFoundException [英] keyNotFoundException when calling WCF client

查看:104
本文介绍了调用WCF客户端时的keyNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个非常简单的wcf服务应用程序,我写的。我已将服务引用添加到我的silverlight应用程序中。但是当我运行应用程序时,它给了我keynotfoundexception。它似乎是我在
IphotoInfoServiceClient上调用new的地方。如果有人可以帮助我,我将非常感激,因为这是我第一次将服务应用程序包含在silverlight应用程序中

 private void Button_Click_1(object sender, RoutedEventArgs e)
{
IphotoInfoServiceClient photoclient = new IphotoInfoServiceClient();

照片photoinfo = new Photo();
photoinfo.Comments = commentBox.Text;
photoinfo.Submitter = NameBox.Text;
Debug.WriteLine(photoinfo.Comments);
Debug.WriteLine(photoinfo.Submitter);

if(commentBox.Text!= null&& NameBox.Text!= null)
{
photoclient.submitPhotoAsync(photoinfo);
}
其他
{
MessageBox.Show("抱歉,输入名称和评论,然后再次尝试发送","缺少姓名或评论",MessageBoxButton.OK );
}
}


命名空间photoServiceLibrary 
{
//这些是方法必须通过此接口实现
[ServiceContract]
公共接口IphotoInfoService
{
[OperationContract]
void submitPhoto(Photo photoinfo);
[OperationContract]
List< Photo> getPhotoInfo();
[OperationContract]
void RemovePhoto(string id);


}
}






<?xml version =" 1.0"编码= QUOT; UTF-8英寸?> 
< configuration>

< system.web>
< compilation debug =" true" />
< /system.web>
<! - 部署服务库项目时,必须将配置文件的内容添加到主机的
app.config文件中。 System.Configuration不支持库的配置文件。 - >
< system.serviceModel>
< services>
< service name =" photoServiceLibrary.PhotoService">
< endpoint address =""结合= QUOT;&的wsHttpBinding QUOT;合同= QUOT; photoServiceLibrary.IphotoInfoService">
< identity>
< dns value =" localhost" />
< / identity>
< / endpoint>
< endpoint address =" mex"结合= QUOT; mexHttpBinding"合同= QUOT; IMetadataExchange接口" />
< host>
< baseAddresses>
< add baseAddress =" http:// localhost:8732 / Design_Time_Addresses / photoServiceLibrary / Service1 /" />
< / baseAddresses>
< / host>
< / service>
< / services>
< behavior>
< serviceBehaviors>
< behavior>
<! - 为了避免公开元数据信息,
将以下值设置为false并在部署之前删除上面的元数据端点 - >
< serviceMetadata httpGetEnabled =" True" />
<! - 为了在调试时接收故障中的异常详细信息,
将下面的值设置为true。在部署
之前设置为false以避免泄露异常信息 - >
< serviceDebug includeExceptionDetailInFaults =" False" />
< / behavior>
< / serviceBehaviors>
< / behavior>
< /system.serviceModel>

< / configuration>





解决方案

如果您导航浏览器中的Web服务是否显示服务页面?


请记住在发布服务时更改服务的URL。


Hello everyone, i have a very simple wcf service application that i have written. I have added the service reference into my silverlight application. But when i run the application it gives me the keynotfoundexception. it seems to be where i call new on the IphotoInfoServiceClient. If anyone can help me out, i will greatly appreciate it, as it is my first time including a service application into a silverlight app

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            IphotoInfoServiceClient photoclient = new IphotoInfoServiceClient();

            Photo photoinfo = new Photo();
            photoinfo.Comments = commentBox.Text;
            photoinfo.Submitter = NameBox.Text;
            Debug.WriteLine(photoinfo.Comments);
            Debug.WriteLine(photoinfo.Submitter);

            if (commentBox.Text != null && NameBox.Text != null)
            {
                photoclient.submitPhotoAsync(photoinfo);
            }
            else
            {
                MessageBox.Show("sorry, enter a name and comment, then trying sending again", "Missing name or comment", MessageBoxButton.OK);
            }
        }

namespace photoServiceLibrary
{
    //these are the methods that must be implemented from this interface
    [ServiceContract]
    public interface IphotoInfoService
    {
        [OperationContract]
        void submitPhoto(Photo photoinfo);
        [OperationContract]
        List<Photo> getPhotoInfo();
        [OperationContract]
        void RemovePhoto(string id);

        
    }
}



<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="photoServiceLibrary.PhotoService">
        <endpoint address="" binding="wsHttpBinding" contract="photoServiceLibrary.IphotoInfoService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/photoServiceLibrary/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>



解决方案

If you navigate to the web service in a browser does the service page show?

Remember to change the url for the service when you publish it.


这篇关于调用WCF客户端时的keyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆