开发Silverlight用的Web服务时遇到的两个问题

今天一时兴起,准备在做个Silverlight程序玩玩。但是遇到了2个问题,废了好几天的时间(幸好不是好几个全天)才解决,发现自己很笨……

1、在从Silverlight项目中添加普通的Web服务引用时,Visual Studio报错:“相对URI不支持此操作”,然后我看引用是添加上了的,在代码中使用什么的都没有问题,但是一到运行时就会抛出异常。最后发现问题出在自动生成的“ServiceReferences.ClientConfig”文件,原来的内容是:

<bindings>
    
<basicHttpBinding>
        
<binding name="UserServiceSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
            
<security mode="None">
                
<transport>
                    
<extendedProtectionPolicy policyEnforcement="Never" />
                
</transport>
            
</security>
        
</binding>
    
</basicHttpBinding>
</bindings>

需要去掉security节的子节点,变成下面那样就可以了:

<bindings>
    
<basicHttpBinding>
        
<binding name="UserServiceSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
            
<security mode="None" />
        
</binding>
    
</basicHttpBinding>
</bindings>

 

2、解决了上面的问题之后,在运行时,又开始报下面这个错误:

The remote server returned an error: NotFound

但是我的各种配置都没有问题,不明白NotFound是个什么概念。最后发现,是因为我的Web方法中会有意通过异常来反馈一些异常情况,而这个异常的抛出就导致这个NotFound的产生,晕啊,这错误提示的驴唇不对马嘴。解决方法就是为Web方法增加一个out参数,如果产生了异常,则通过这个out参数反馈。

posted on 2009-04-08 14:58  零度的火  阅读(621)  评论(0编辑  收藏  举报

导航