远程服务器返回错误:NotFound.例外 [英] The remote server returned an error: NotFound. Exception
本文介绍了远程服务器返回错误:NotFound.例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
我在Silverlight应用程序中使用WCF.
当我从应用程序调用WCF函数时,调用了未找到的异常远程服务器返回错误:NotFound".
我的代码........................
Page.xaml.cs文件
Hi friends
I am using WCF in silverlight application.
when i am calling the WCF function calling from the application than found Exception "The remote server returned an error: NotFound."
My code........................
Page.xaml.cs file
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
ServiceReference1.Service1Client ss = new ServiceReference1.Service1Client();
ss.GetProjectCompleted += new EventHandler<silverlightapplication1.servicereference1.getprojectcompletedeventargs>(check);
ss.GetProjectAsync("");
}
public static void check(Object sender, ServiceReference1.GetProjectCompletedEventArgs e)
{
string a = e.Result.ToString();
}
}
}
Reference.cs file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3603
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
//
// This code was auto-generated by Microsoft.Silverlight.ServiceReference, version 3.0.40818.0
//
namespace SilverlightApplication1.ServiceReference1 {
using System.Runtime.Serialization;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="CompositeType", Namespace="http://schemas.datacontract.org/2004/07/LaborService")]
public partial class CompositeType : object, System.ComponentModel.INotifyPropertyChanged {
private bool BoolValueField;
private string StringValueField;
[System.Runtime.Serialization.DataMemberAttribute()]
public bool BoolValue {
get {
return this.BoolValueField;
}
set {
if ((this.BoolValueField.Equals(value) != true)) {
this.BoolValueField = value;
this.RaisePropertyChanged("BoolValue");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string StringValue {
get {
return this.StringValueField;
}
set {
if ((object.ReferenceEquals(this.StringValueField, value) != true)) {
this.StringValueField = value;
this.RaisePropertyChanged("StringValue");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ServiceReference1.IService1")]
public interface IService1 {
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IService1/GetData", ReplyAction="http://tempuri.org/IService1/GetDataResponse")]
System.IAsyncResult BeginGetData(int value, System.AsyncCallback callback, object asyncState);
string EndGetData(System.IAsyncResult result);
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IService1/GetDataUsingDataContract", ReplyAction="http://tempuri.org/IService1/GetDataUsingDataContractResponse")]
System.IAsyncResult BeginGetDataUsingDataContract(SilverlightApplication1.ServiceReference1.CompositeType composite, System.AsyncCallback callback, object asyncState);
SilverlightApplication1.ServiceReference1.CompositeType EndGetDataUsingDataContract(System.IAsyncResult result);
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://tempuri.org/IService1/GetProject", ReplyAction="http://tempuri.org/IService1/GetProjectResponse")]
System.IAsyncResult BeginGetProject(string index, System.AsyncCallback callback, object asyncState);
string EndGetProject(System.IAsyncResult result);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public interface IService1Channel : SilverlightApplication1.ServiceReference1.IService1, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
public string Result {
get {
base.RaiseExceptionIfNecessary();
return ((string)(this.results[0]));
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class GetDataUsingDataContractCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
public GetDataUsingDataContractCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
public SilverlightApplication1.ServiceReference1.CompositeType Result {
get {
base.RaiseExceptionIfNecessary();
return ((SilverlightApplication1.ServiceReference1.CompositeType)(this.results[0]));
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class GetProjectCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
public GetProjectCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
public string Result {
get {
base.RaiseExceptionIfNecessary();
return ((string)(this.results[0]));
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase<silverlightapplication1.servicereference1.iservice1>, SilverlightApplication1.ServiceReference1.IService1 {
private BeginOperationDelegate onBeginGetDataDelegate;
private EndOperationDelegate onEndGetDataDelegate;
private System.Threading.SendOrPostCallback onGetDataCompletedDelegate;
private BeginOperationDelegate onBeginGetDataUsingDataContractDelegate;
private EndOperationDelegate onEndGetDataUsingDataContractDelegate;
private System.Threading.SendOrPostCallback onGetDataUsingDataContractCompletedDelegate;
private BeginOperationDelegate onBeginGetProjectDelegate;
private EndOperationDelegate onEndGetProjectDelegate;
private System.Threading.SendOrPostCallback onGetProjectCompletedDelegate;
private BeginOperationDelegate onBeginOpenDelegate;
private EndOperationDelegate onEndOpenDelegate;
private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
private BeginOperationDelegate onBeginCloseDelegate;
private EndOperationDelegate onEndCloseDelegate;
private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
public Service1Client() {
}
public Service1Client(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public Service1Client(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
public System.Net.CookieContainer CookieContainer {
get {
System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<system.servicemodel.channels.ihttpcookiecontainermanager>();
if ((httpCookieContainerManager != null)) {
return httpCookieContainerManager.CookieContainer;
}
else {
return null;
}
}
set {
System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<system.servicemodel.channels.ihttpcookiecontainermanager>();
if ((httpCookieContainerManager != null)) {
httpCookieContainerManager.CookieContainer = value;
}
else {
throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
"ookieContainerBindingElement.");
}
}
}
public event System.EventHandler<getdatacompletedeventargs> GetDataCompleted;
public event System.EventHandler<getdatausingdatacontractcompletedeventargs> GetDataUsingDataContractCompleted;
public event System.EventHandler<getprojectcompletedeventargs> GetProjectCompleted;
public event System.EventHandler<system.componentmodel.asynccompletedeventargs> OpenCompleted;
public event System.EventHandler<system.componentmodel.asynccompletedeventargs> CloseCompleted;
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult SilverlightApplication1.ServiceReference1.IService1.BeginGetData(int value, System.AsyncCallback callback, object asyncState) {
return base.Channel.BeginGetData(value, callback, asyncState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
string SilverlightApplication1.ServiceReference1.IService1.EndGetData(System.IAsyncResult result) {
return base.Channel.EndGetData(result);
}
private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState) {
int value = ((int)(inValues[0]));
return ((SilverlightApplication1.ServiceReference1.IService1)(this)).BeginGetData(value, callback, asyncState);
}
private object[] OnEndGetData(System.IAsyncResult result) {
string retVal = ((SilverlightApplication1.ServiceReference1.IService1)(this)).EndGetData(result);
return new object[] {
retVal};
}
private void OnGetDataCompleted(object state) {
if ((this.GetDataCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
}
}
public void GetDataAsync(int value) {
this.GetDataAsync(value, null);
}
public void GetDataAsync(int value, object userState) {
if ((this.onBeginGetDataDelegate == null)) {
this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData);
}
if ((this.onEndGetDataDelegate == null)) {
this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData);
}
if ((this.onGetDataCompletedDelegate == null)) {
this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted);
}
base.InvokeAsync(this.onBeginGetDataDelegate, new object[] {
value}, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, userState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult SilverlightApplication1.ServiceReference1.IService1.BeginGetDataUsingDataContract(SilverlightApplication1.ServiceReference1.CompositeType composite, System.AsyncCallback callback, object asyncState) {
return base.Channel.BeginGetDataUsingDataContract(composite, callback, asyncState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
SilverlightApplication1.ServiceReference1.CompositeType SilverlightApplication1.ServiceReference1.IService1.EndGetDataUsingDataContract(System.IAsyncResult result) {
return base.Channel.EndGetDataUsingDataContract(result);
}
private System.IAsyncResult OnBeginGetDataUsingDataContract(object[] inValues, System.AsyncCallback callback, object asyncState) {
SilverlightApplication1.ServiceReference1.CompositeType composite = ((SilverlightApplication1.ServiceReference1.CompositeType)(inValues[0]));
return ((SilverlightApplication1.ServiceReference1.IService1)(this)).BeginGetDataUsingDataContract(composite, callback, asyncState);
}
private object[] OnEndGetDataUsingDataContract(System.IAsyncResult result) {
SilverlightApplication1.ServiceReference1.CompositeType retVal = ((SilverlightApplication1.ServiceReference1.IService1)(this)).EndGetDataUsingDataContract(result);
return new object[] {
retVal};
}
private void OnGetDataUsingDataContractCompleted(object state) {
if ((this.GetDataUsingDataContractCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.GetDataUsingDataContractCompleted(this, new GetDataUsingDataContractCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
}
}
public void GetDataUsingDataContractAsync(SilverlightApplication1.ServiceReference1.CompositeType composite) {
this.GetDataUsingDataContractAsync(composite, null);
}
public void GetDataUsingDataContractAsync(SilverlightApplication1.ServiceReference1.CompositeType composite, object userState) {
if ((this.onBeginGetDataUsingDataContractDelegate == null)) {
this.onBeginGetDataUsingDataContractDelegate = new BeginOperationDelegate(this.OnBeginGetDataUsingDataContract);
}
if ((this.onEndGetDataUsingDataContractDelegate == null)) {
this.onEndGetDataUsingDataContractDelegate = new EndOperationDelegate(this.OnEndGetDataUsingDataContract);
}
if ((this.onGetDataUsingDataContractCompletedDelegate == null)) {
this.onGetDataUsingDataContractCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataUsingDataContractCompleted);
}
base.InvokeAsync(this.onBeginGetDataUsingDataContractDelegate, new object[] {
composite}, this.onEndGetDataUsingDataContractDelegate, this.onGetDataUsingDataContractCompletedDelegate, userState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult SilverlightApplication1.ServiceReference1.IService1.BeginGetProject(string index, System.AsyncCallback callback, object asyncState) {
return base.Channel.BeginGetProject(index, callback, asyncState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
string SilverlightApplication1.ServiceReference1.IService1.EndGetProject(System.IAsyncResult result) {
return base.Channel.EndGetProject(result);
}
private System.IAsyncResult OnBeginGetProject(object[] inValues, System.AsyncCallback callback, object asyncState) {
string index = ((string)(inValues[0]));
return ((SilverlightApplication1.ServiceReference1.IService1)(this)).BeginGetProject(index, callback, asyncState);
}
private object[] OnEndGetProject(System.IAsyncResult result) {
string retVal = ((SilverlightApplication1.ServiceReference1.IService1)(this)).EndGetProject(result);
return new object[] {
retVal};
}
private void OnGetProjectCompleted(object state) {
if ((this.GetProjectCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.GetProjectCompleted(this, new GetProjectCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
}
}
public void GetProjectAsync(string index) {
this.GetProjectAsync(index, null);
}
public void GetProjectAsync(string index, object userState) {
if ((this.onBeginGetProjectDelegate == null)) {
this.onBeginGetProjectDelegate = new BeginOperationDelegate(this.OnBeginGetProject);
}
if ((this.onEndGetProjectDelegate == null)) {
this.onEndGetProjectDelegate = new EndOperationDelegate(this.OnEndGetProject);
}
if ((this.onGetProjectCompletedDelegate == null)) {
this.onGetProjectCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetProjectCompleted);
}
base.InvokeAsync(this.onBeginGetProjectDelegate, new object[] {
index}, this.onEndGetProjectDelegate, this.onGetProjectCompletedDelegate, userState);
}
private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) {
return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
}
private object[] OnEndOpen(System.IAsyncResult result) {
((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
return null;
}
private void OnOpenCompleted(object state) {
if ((this.OpenCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
public void OpenAsync() {
this.OpenAsync(null);
}
public void OpenAsync(object userState) {
if ((this.onBeginOpenDelegate == null)) {
this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
}
if ((this.onEndOpenDelegate == null)) {
this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
}
if ((this.onOpenCompletedDelegate == null)) {
this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
}
base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
}
private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) {
return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
}
private object[] OnEndClose(System.IAsyncResult result) {
((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
return null;
}
private void OnCloseCompleted(object state) {
if ((this.CloseCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
public void CloseAsync() {
this.CloseAsync(null);
}
public void CloseAsync(object userState) {
if ((this.onBeginCloseDelegate == null)) {
this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
}
if ((this.onEndCloseDelegate == null)) {
this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
}
if ((this.onCloseCompletedDelegate == null)) {
this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
}
base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
}
protected override SilverlightApplication1.ServiceReference1.IService1 CreateChannel() {
return new Service1ClientChannel(this);
}
private class Service1ClientChannel : ChannelBase<silverlightapplication1.servicereference1.iservice1>, SilverlightApplication1.ServiceReference1.IService1 {
public Service1ClientChannel(System.ServiceModel.ClientBase<silverlightapplication1.servicereference1.iservice1> client) :
base(client) {
}
public System.IAsyncResult BeginGetData(int value, System.AsyncCallback callback, object asyncState) {
object[] _args = new object[1];
_args[0] = value;
System.IAsyncResult _result = base.BeginInvoke("GetData", _args, callback, asyncState);
return _result;
}
public string EndGetData(System.IAsyncResult result) {
object[] _args = new object[0];
string _result = ((string)(base.EndInvoke("GetData", _args, result)));
return _result;
}
public System.IAsyncResult BeginGetDataUsingDataContract(SilverlightApplication1.ServiceReference1.CompositeType composite, System.AsyncCallback callback, object asyncState) {
object[] _args = new object[1];
_args[0] = composite;
System.IAsyncResult _result = base.BeginInvoke("GetDataUsingDataContract", _args, callback, asyncState);
return _result;
}
public SilverlightApplication1.ServiceReference1.CompositeType EndGetDataUsingDataContract(System.IAsyncResult result) {
object[] _args = new object[0];
SilverlightApplication1.ServiceReference1.CompositeType _result = ((SilverlightApplication1.ServiceReference1.CompositeType)(base.EndInvoke("GetDataUsingDataContract", _args, result)));
return _result;
}
public System.IAsyncResult BeginGetProject(string index, System.AsyncCallback callback, object asyncState) {
object[] _args = new object[1];
_args[0] = index;
System.IAsyncResult _result = base.BeginInvoke("GetProject", _args, callback, asyncState);
return _result;
}
public string EndGetProject(System.IAsyncResult result) {
object[] _args = new object[0];
string _result = ((string)(base.EndInvoke("GetProject", _args, result)));
return _result;
}
}
}
}
My WCF file..
Service1.svc.vb...
My WCF file..
Service1.svc.vb...
Public Class MyService
Implements IService1
Public Sub New()
End Sub
Public Function GetData(ByVal value As Integer) As String Implements IService1.GetData
Return String.Format("You entered: {0}", value)
End Function
Public Function GetDataUsingDataContract(ByVal composite As CompositeType) As CompositeType Implements IService1.GetDataUsingDataContract
If composite.BoolValue Then
composite.StringValue = (composite.StringValue & "Suffix")
End If
Return composite
End Function
Public Function GetProject(ByVal index As String) As String Implements IService1.GetProject
Return "Hai"
End Function
End Class
Something I am missing please help me
Thanks in advance..........
Upniwesh
Something I am missing please help me
Thanks in advance..........
Upniwesh
推荐答案
Nobody here is free enough to go through all your code. But the general reason for this error is
1. Misconfiguration of web.config
2. Service is not hosted on the path you are accessing from.
I recommend you to go through your web.config again. That is the most probable reason for error.
Nobody here is free enough to go through all your code. But the general reason for this error is
1. Misconfiguration of web.config
2. Service is not hosted on the path you are accessing from.
I recommend you to go through your web.config again. That is the most probable reason for error.
这篇关于远程服务器返回错误:NotFound.例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文