简体   繁体   中英

Merging WCF webservice to my web application returns an exception

I would like to add an reference for WCF weather forecast webservice in my application.The thing is I have done everything correctly,but i am lacking somewhere else.It throws an Exception.The Exception message is in the bottom of this post.Somebody out there please help me to fix this.Unles or until fixing this i couln't move to the next phase.

My Source Code is here:

public partial class Testing : System.Web.UI.Page
    {
        weather.WeatherForecastServiceClient ws = new weather.WeatherForecastServiceClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary<string, string> objDic = new SortedDictionary<string, string>();
            foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name);
                if (!objDic.ContainsKey(objRegionInfo.EnglishName))
                {
                    objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name);
                }
            }
        foreach (KeyValuePair<string, string> val in objDic)
        {
            Country.Items.Add(new ListItem(val.Key, val.Value));
        }

    }

    protected void callwebservice_Click(object sender, EventArgs e)
    {

            Result.Text = "Result" + ws.GetForecastByCity(City.SelectedItem.ToString(), Country.SelectedItem.ToString());

    }

    protected void Country_SelectedIndexChanged(object sender, EventArgs e)
    {
        string[] cities = ws.GetCitiesByCountry(Country.SelectedItem.ToString());
        City.DataSource = cities;
        City.DataBind();
    }
}

This is my Exception

    Server Error in '/' Application.

    **The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
    Source Error: 
    Line 310:        
    Line 311:        public testing.weather.Weather GetForecastByCity(string City, string Country) {
    Line 312:            return base.Channel.GetForecastByCity(City, Country);
    Line 313:        }
    Line 314:    }
Source File: E:\***\WeatherForecast\testing\Service References\weather\Reference.cs    Line: 312 

Stack Trace: 


[FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9442991
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   testing.weather.IWeatherForecastService.GetForecastByCity(String City, String Country) +0
   testing.weather.WeatherForecastServiceClient.GetForecastByCity(String City, String Country) in E:\sasi\WeatherForecast\testing\Service References\weather\Reference.cs:312
   testing.Testing.callwebservice_Click(Object sender, EventArgs e) in E:\sasi\WeatherForecast\testing\Testing.aspx.cs:40
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272**

You have implemented the service correctly. You can confirm this by running GetCitiesByCountry (it will return a list of cities). It is just that the method GetForecastByCity does not currently work.

Try any of these APIs instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM