2010-02-16 2 views
1

WCF syndicationlibrary 템플리트에 OperationContract를 추가하려고 시도하지만 URI 템플리트가 일치하지 않거나 다른 내용이 누락 된 것 같습니다. wcf syndicationlibrary 템플리트에 operationContract를 추가하지 못했습니다.

내가가 발생하지 않습니다 http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2/ShowDocument?url=http://www.test.com

기능 showDocument 메소드에 접근하려고 할 때 나는 404 오류가 발생합니다.

도움을 주시면 감사하겠습니다.

IFeed1.cs :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Syndication; 
using System.ServiceModel.Web; 
using System.Text; 

namespace SyndicationServiceLibrary2 
{ 
    // NOTE: If you change the interface name "IFeed1" here, you must also update the reference to "IFeed1" in App.config. 
    [ServiceContract] 
    [ServiceKnownType(typeof(Atom10FeedFormatter))] 
    [ServiceKnownType(typeof(Rss20FeedFormatter))] 
    public interface IFeed1 
    { 

     [OperationContract] 
     [WebGet(UriTemplate = "*", BodyStyle = WebMessageBodyStyle.Bare)] 
     SyndicationFeedFormatter CreateFeed(); 

     [OperationContract] 
     [WebInvoke(UriTemplate = "/ShowDocument?*", BodyStyle = WebMessageBodyStyle.Bare)] 
     int ShowDocument(); 

     // TODO: Add your service operations here 
    } 
} 

Feed1.cs :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.ServiceModel; 
using System.ServiceModel.Syndication; 
using System.ServiceModel.Web; 
using System.Text; 

namespace SyndicationServiceLibrary2 
{ 
    // NOTE: If you change the class name "Feed1" here, you must also update the reference to "Feed1" in App.config. 
    public class Feed1 : IFeed1 
    { 
     public int ShowDocument() 
     { 
      int test = 0; 
      return test; 
     } 

     public SyndicationFeedFormatter CreateFeed() 
     { 
      // Create a new Syndication Feed. 
      SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null); 
      List<SyndicationItem> items = new List<SyndicationItem>(); 

      // Create a new Syndication Item. 
      SyndicationItem item = new SyndicationItem("An item", "Item content", new Uri("http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2/ShowDocument?url=http://www.test.com")); 

      items.Add(item); 
      feed.Items = items; 

      string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"]; 
      SyndicationFeedFormatter formatter = null; 

      if (query == "atom") 
      { 
       formatter = new Atom10FeedFormatter(feed); 
      } 
      else 
      { 
       formatter = new Rss20FeedFormatter(feed); 
      } 

      return formatter; 
     } 
    } 
} 
+0

@Bruno : 당신은 코드 또는 XML을 게시 할 경우, ** ** 그 라인을 강조하고 적절하게 그 라인의 서식 편집기 도구 모음의 "코드"버튼 (101 010)를 사용합니다 (그들을 잘 syntax- 얻으십시오 강조 표시됨) - 감사합니다! –

답변

0

지금은 그것을 자신을 시도 할 수 없음 - 몇 가지 아이디어를 내 머리 위로 떨어져 :

매개 변수로 Url 인코딩을 사용해 보셨습니까 ??

http://......./ShowDocument?url=http%3a%2f%2fwww.test.com 

이 도움이 될 수 있습니다 - URL 자체에 갈 필요가 인코딩 (디코딩) 매개 변수를 URL로 System.Web 네임 스페이스에서 HttpUtility.UrlEncode 방법을 사용합니다.

또 다른 아이디어 : URL 템플릿을 만들고 URL을 ShowDocument 문자열로 전달하는 방법은 무엇입니까 ??

[OperationContract] 
[WebInvoke(UriTemplate = "/ShowDocument?url={target}", BodyStyle = WebMessageBodyStyle.Bare)] 
int ShowDocument(string target); 

하고 그 다음 작동하는지? 난 당신이 내 문제를 말할 부끄러워

0

이었다 "MYSERVER"는 좋은

new Uri("http://myserver:8738/Design_Time_Addresses/SyndicationServiceLibrary2... 

되지 않은 경우.

나는 마침내 매개 변수를 사용하여 URL 템플릿을 사용하여 모든 일을 할 수 있었다.

관련 문제