为什么在WebServices中无法使用WebClient?

haiwangstar 2006-09-09 11:14:21
我做了一个非常简单WebServices,其中有一个部分是使用WebClient下载别的网站上的图像,但是在调用DownloadFile时出现了异常,提示是无法建立远程连接。我用做一个WinForm的程序试了下,可以下载的。

是权限的问题吗? 大家有遇到过这样的问题吗? 该怎么解决? 谢谢!
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2006-09-10
  • 打赏
  • 举报
回复
大致代码如何写得,在哪儿调用的
Overriding 2006-09-10
  • 打赏
  • 举报
回复
楼主考虑其他地方的错误吧!

这个肯定是能用的,我在webservice里用xmlhttp写过,是可以的,那webclient也应该可以。

haiwangstar 2006-09-10
  • 打赏
  • 举报
回复
算了。结贴。
haiwangstar 2006-09-10
  • 打赏
  • 举报
回复
谢谢大家! 今天重新运行,什么都没有改,又可以了,可能是机器有了点问题。
另外,还有个小问题。也是非常蹊跷,就是用ASP.NET
sxlfybb 2006-09-09
  • 打赏
  • 举报
回复
没碰过,不过我的理解是
WebServices是网络服务,意味着是remote调用,现在在romote进行downfile工作.可能会有问题.
具体我也没测试.
haiwangstar 2006-09-09
  • 打赏
  • 举报
回复
在WebServices中使用WebClient肯定是可以的,因为我看到过有人用WebClient来查询远程的WebServices,但为什么会出现这样的问题。。真的是想不清楚。
微软Windows® Phone推送通知服务(PushNotificationService)为第三方开发者提供了一个弹性、专注、可持续的通道,支持发送消息、从服务器(web services)端更新Windows® Phone应用程序。 在这一部分,一个移动应用程序需要经常的查看对应的web service,以了解是否有未处理的Notification。如果保持有效状态,就会造成设备的手机模块始终处于打开状态,进而影响待机时间。如果使用Push Notifications,Web Service只要在重要的更新时,才会通知到应用程序。 Figure1 PushNotifications 当Web Service有信息需要发送到应用程序时,它发送一个Push Notification到微软的PushNotificationService服务器上,然后会将这个Push Notification转发给应用程序。依赖于Push Notification的格式和负载量,这个信息会有三种形式展现:作为原始数据发布给应用程序,应用程序的Tile将更新,或者弹出一个Toast notification。如果需要,应用程序可以使用自有的协议来与Web Service通讯。 在Push Notification被发送之后,PushNotificationService服务器会发送一个响应代码到您的Web Service。事实上,PushNotificationService不会提供您的推送通知从您的Web Service到应用程序之间的端到端确认方式。更多信息,请参考PushNotificationServiceResponseCodesforWindows®Phone. 本次动手实验将会覆盖推送通知,并介绍Silverlighthttp服务的用法。在整个实验,您将会创建服务器端的逻辑,用来发送消息到Push Notification Service。您也会创建一个简单的Windows® Phone 7 Mango应用程序,作为客户端,用来接收推送通知。客户端应用程序将会接收天气更新。服务器端的业务应用程序(一个简单的WPF应用)将会发送天气提醒道已经通过Push Notification Services注册的客户端应用程序上去。一旦Windows® Phone 7客户端应用程序接收到提醒,将会显示接收到的信息。 提示:服务器端的天气应用程序使用WindowsPhone.Recipes.Push.Messasges.dll,封装了所有发送、从Microsoft Push Notification Services接受响应的业务逻辑和功能。更多信息请参考:http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx. 目标 在本次实验课程,您将会: • 熟悉Windows® Phone 7应用程序的通讯功能 • 熟悉Push Notification的概念和在手机上的使用行为 • 理解Push Notifications在云端和手机端如何工作 • 使用手机Push Notifications服务,创建一个Tokens (tiles), Toasts, 和 raw push notifications的订阅 • 使用WebClient注册PushNotifications • 使用Networkstatus来显示当前手机网络的状态 • 创建一个SL应用程序,用来注册pushnotificationservices(包括token和toast) ◦ 运行期控制push事件events(token,toast,和raw) ◦ 在Shell显示token和toast信息 • 管理应用程序独立更新的sub-tiles,并链接到应用程序的制定位置(仅在Windows®Phone7.1有效)
动态调用WebService的方法类,可以不用在VS本地引用,直接动态调用即可。 样例如下: /// /// 实例化WebServices /// /// WebServices地址 /// 调用的方法 /// 把webservices里需要的参数按顺序放到这个object[]里 public static object InvokeWebService(string url, string methodname, object[] args) { //这里的namespace是需引用的webservices的命名空间,我没有改过,也可以使用。也可以加一个参数从外面传进来。 //string @namespace = "Nq.Application.WebService"; string @namespace = "client"; try { //获取WSDL WebClient wc = new WebClient(); //Stream stream = wc.OpenRead(url); Stream stream = wc.OpenRead(url + "?WSDL"); ServiceDescription sd = ServiceDescription.Read(stream); string classname = sd.Services[0].Name; ServiceDescriptionImporter sdi = new ServiceDescriptionImporter(); sdi.AddServiceDescription(sd, "", ""); CodeNamespace cn = new CodeNamespace(@namespace); //生成客户端代理类代码 CodeCompileUnit ccu = new CodeCompileUnit(); ccu.Namespaces.Add(cn); sdi.Import(cn, ccu); CSharpCodeProvider csc = new CSharpCodeProvider(); //ICodeCompiler icc = csc.CreateCompiler(); //设定编译参数 CompilerParameters cplist = new CompilerParameters(); cplist.GenerateExecutable = false;//动态编译后的程序集不生成可执行文件 cplist.GenerateInMemory = true;//动态编译后的程序集只存在于内存,不在硬盘的文件上 cplist.ReferencedAssemblies.Add("System.dll"); cplist.ReferencedAssemblies.Add("System.XML.dll"); cplist.ReferencedAssemblies.Add("System.Web.Services.dll"); cplist.ReferencedAssemblies.Add("System.Data.dll"); //编译代理类 CompilerResults cr =
Beginning: Microsoft Visual C# 2008 0 About the Authors 9 Credits 10 Contents 12 Introduction 30 Who This Book Is For 30 How This Book Is Structured 31 What You Need to Use This Book 34 Conventions 34 Source Code 35 Errata 35 p2p.wrox.com 36 Part I: The C# Language 38 Chapter 1: Introducing C# 40 What Is the .NET Framework? 40 What Is C#? 45 Visual Studio 2008 46 Summary 48 Chapter 2: Writing a C# Program 50 The Development Environments 51 Console Applications 55 Windows Forms Applications 61 Summary 66 Chapter 3: Variables and Expressions 68 Basic C# Syntax 69 Basic C# Console Application Structure 71 Variables 73 Expressions 83 Summary 93 Exercises 94 Chapter 4: Flow Control 96 Boolean Logic 96 The goto Statement 106 Branching 107 Looping 115 Summary 127 Exercises 127 Chapter 5: More About Variables 130 Type Conversion 130 Complex Variable Types 140 String Manipulation 155 Summary 160 Exercises 161 Chapter 6: Functions 162 Defining and Using Functions 163 Variable Scope 175 The Main() Function 181 Struct Functions 184 Overloading Functions 185 Delegates 187 Summary 190 Exercises 191 Chapter 7: Debugging and Error Handling 192 Debugging in VS and VCE 193 Error Handling 213 Summary 221 Exercises 221 Chapter 8: Introduction to Object-Oriented Programming 222 What Is Object-Oriented Programming? 223 OOP Techniques 229 OOP in Windows Applications 240 Summary 243 Exercises 243 Chapter 9: Defining Classes 246 Class Definitions in C# 246 System.Object 253 Constructors and Destructors 255 OOP Tools in VS and VCE 260 Class Library Projects 266 Interfaces Versus Abstract Classes 270 Struct Types 272 Summary 275 Exercises 276 Chapter 10: Defining Class Members 278 Member Definitions 278 Additional Class Member Topics 291 Interface Implementation 294 Partial Class Definitions 299 Partial Method Definitions 301 Example Application 302 Summary 313 Exercises 313 Chapter 11: Collections, Comparisons, and Conversions 314 Collections 314 Comparisons 340 Conversions 363 Summary 365 Exercises 366 Chapter 12: Generics 368 What Is a Generic? 368 Using Generics 370 Defining Generics 388 Summary 405 Exercises 405 Chapter 13: Additional OOP Techniques 408 The :: Operator and the Global Namespace Qualifier 408 Custom Exceptions 410 Events 412 Expanding and Using CardLib 426 Summary 434 Exercises 435 Chapter 14: C# 3.0 Language Enhancements 436 Initializers 437 Type Inference 443 Anonymous Types 445 Extension Methods 449 Lambda Expressions 455 Summary 466 Exercises 467 Part II: Windows Programming 468 Chapter 15: Basic Windows Programming 470 Controls 471 The Button Control 477 The Label and LinkLabel Controls 480 The TextBox Control 481 The RadioButton and CheckBox Controls 491 The RichTextBox Control 498 The ListBox and CheckedListBox Controls 506 The ListView Control 512 The TabControl Control 523 Summary 528 Exercises 529 Chapter 16: Advanced Windows Forms Features 530 Menus and Toolbars 531 Toolbars 538 SDI and MDI Applications 549 Creating Controls 561 Summary 572 Exercises 572 Chapter 17: Using Common Dialogs 574 Common Dialogs 574 How to Use Dialogs 576 File Dialogs 577 Printing 596 Print Preview 612 FontDialog and ColorDialog 614 Summary 618 Exercises 619 Chapter 18: Deploying Windows Applications 620 Deployment Overview 620 ClickOnce Deployment 621 Visual Studio Setup and Deployment Project Types 634 Microsoft Windows Installer Architecture 635 Creating an Installation Package for the SimpleEditor 639 Building the Project 654 Installation 654 Summary 659 Exercises 660 Part III: Web Programming 662 Chapter 19: Basic Web Programming 664 Overview 665 ASP.NET Runtime 665 Creating a Simple Page 666 Server Controls 673 Event Handlers 674 Input Validation 679 State Management 683 Authentication and Authorization 689 Reading and Writing to an SQL Server Database 697 Summary 706 Exercises 707 Chapter 20: Advanced Web Programming 708 Master Pages 708 Site Navigation 716 User Controls 717 Profiles 720 Web Parts 725 JavaScript 738 Summary 744 Exercises 745 Chapter 21: Web Services 746 Before Web Services 747 Where to Use Web Services 748 Web Services Architecture 751 Web Services and the .NET Framework 754 Creating a Simple ASP.NET Web Service 757 Testing the Web Service 759 Implementing a Windows Client 761 Calling the Service Asynchronously 765 Implementing an ASP.NET Client 768 Passing Data 769 Summary 773 Exercises 774 Chapter 22: Ajax Programming 776 Ajax Overview 776 Update Panel 778 Timer Control 783 Update Progress 784 Web Services 786 Extender Controls 792 Summary 794 Exercises 794 Chapter 23: Deploying Web Applications 796 Internet Information Services 796 IIS Configuration 797 Copying a Web Site 800 Publishing a Web Site 802 Windows Installer 804 Summary 809 Exercises 810 Part IV: Data Access 812 Chapter 24: File System Data 814 Streams 815 The Classes for Input and Output 815 Serialized Objects 842 Monitoring the File Structure 847 Summary 855 Exercises 855 Chapter 25: XML 856 XML Documents 856 Using XML in Your Application 865 Summary 884 Exercises 885 Chapter 26: Introduction to LINQ 886 LINQ Varieties 887 First LINQ Query 887 Using the LINQ Method Syntax and Lambda Expressions 892 Ordering Query Results 895 orderby Clause 897 Ordering Using Method Syntax 897 Querying a Large Data Set 899 Aggregate Operators 902 Querying Complex Objects 905 Projection: Creating New Objects in Queries 909 Projection: Method Syntax 912 Select Distinct Query 912 Any and All 914 Ordering By Multiple Levels 916 Multi-Level Ordering Method Syntax: ThenBy 918 Group Queries 918 Take and Skip 920 First and FirstOrDefault 923 Set Operators 924 Joins 928 Resources and Further Reading 929 Summary 930 Exercises 930 Chapter 27: LINQ to SQL 932 Object -Relational Mapping (ORM) 933 Installing SQL Server and the Northwind Sample Data 933 First LINQ to SQL Query 935 Navigating LINQ to SQL Relationships 944 Drilling Down Further with LINQ to SQL 948 Grouping, Ordering, and Other Advanced Queries in LINQ to SQL 951 Displaying Generated SQL 954 Data Binding with LINQ to SQL 958 Updating Bound Data with LINQ to SQL 965 Summary 966 Exercises 967 Chapter 28: ADO.NET and LINQ over DataSet 970 What Is ADO.NET? 971 Overview of ADO.NET Classes and Objects 974 Reading Data with the DataReader 977 Reading Data with the DataSet 985 Updating the Database 989 Accessing Multiple Tables in a DataSet 1002 XML and ADO.NET 1010 SQL Support in ADO.NET 1014 Using LINQ over DataSet with ADO.NET 1022 Summary 1027 Exercises 1027 Chapter 29: LINQ to XML 1030 LINQ to XML Functional Constructors 1031 Saving and Loading an XML Document 1035 Working with XML Fragments 1039 Generating XML from LINQ to SQL 1041 How to Query an XML Document 1046 Summary 1053 Exercises 1053 Part V: Additional Techniques 1054 Chapter 30: Attributes 1056 What Is an Attribute? 1056 Reflection 1060 Built-in Attributes 1063 Custom Attributes 1075 Summary 1083 Chapter 31: XML Documentation 1086 Adding XML Documentation 1087 Making Use of XML Documentation 1105 Summary 1110 Exercises 1110 Chapter 32: Networking 1112 Networking Overview 1112 Networking Programming Options 1120 WebClient 1121 WebRequest and WebResponse 1123 TcpListener and TcpClient 1133 Summary 1141 Exercises 1142 Chapter 33: Introduction to GDI+ 1144 Overview of Graphical Drawing 1145 Drawing Lines Using the Pen Class 1156 Drawing Shapes Using the Brush Class 1159 Drawing Text Using the Font Class 1161 Drawing Using Images 1165 Advanced Capabilities of GDI+ 1175 Summary 1177 Exercises 1178 Chapter 34: Windows Presentation Foundation 1180 What Is WPF? 1181 Anatomy of a Basic WPF Application 1185 WPF Fundamentals 1197 Programming with WPF 1237 Summary 1249 Exercises 1250 Chapter 35: Windows Communication Foundation 1252 What Is WCF ? 1253 WCF Concepts 1254 WCF Programming 1258 Summary 1282 Exercises 1283 Chapter 36: Windows Workflow Foundation 1284 Activities 1288 The Workflow Runtime 1303 Data Binding 1310 Summary 1315 Index 1316

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧